如何在 sharepoint 2013 中获得 oauth 访问令牌? [英] How can I get an oauth access token in sharepoint 2013?

查看:33
本文介绍了如何在 sharepoint 2013 中获得 oauth 访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有这个网站:http://msdn.microsoft.com/en-us/library/jj164022(v=office.15).aspx

部分文字说:以下 JavaScript 代码演示了如何使用 JQuery 发出此 GET 请求,该请求返回所有站点列表的 JSON 表示.它还假设您拥有存储在 accessToken 变量中的有效 OAuth 访问令牌.如果您从应用 Web 内部进行此调用,则不需要访问令牌,就像在 SharePoint 托管的应用中一样.

the text in some part says: The following JavaScript code demonstrates how to make this GET request that returns a JSON representation of all of a site’s lists by using JQuery. It also assumes that you have a valid OAuth access token that is stored in the accessToken variable. You do not need the access token if you make this call from inside an app web, as you would in a SharePoint-hosted app.

jQuery.ajax({
url: http:// site url/_api/web/lists,
type: "GET",
headers: {
"ACCEPT","application/json;odata=verbose",
"Authorization", "Bearer " + accessToken
},
})

具体问题是如何获取访问令牌??

the specific question is how can I get the access token??

推荐答案

您的整个方法都不正确.在使用 javascript 访问 sharepoint 2013 服务器的 REST 服务时,您不需要访问令牌.您必须改用 Sharepoint 2013 跨域库.

Your entire approach is incorrect. When it comes to accessing the REST services of a sharepoint 2013 server using javascript you don't need an Access Token. You have to use the Sharepoint 2013 cross-domain library instead.

位于 http://msdn.microsoft.com/en-us 的页面/library/jj164022.aspx 在显示使用 oauth 令牌的经典 REST 请求后解释:

The page at http://msdn.microsoft.com/en-us/library/jj164022.aspx explains after showing a classic REST request using an oauth token:

如果您使用 JavaScript 编写应用程序但使用 SharePoint 2013 跨域库,则此请求看起来会有所不同.在这种情况下,您不需要提供访问令牌.以下代码演示了如果您使用跨域库并希望以 XML 而不是 JSON 的形式接收列表的 OData 表示形式,此请求的外观.有关使用跨域库的详细信息,请参阅如何:使用跨域库从远程应用访问 SharePoint 2013 数据.

This request would look a little different if you are writing your app in JavaScript but using the SharePoint 2013 cross-domain library. In this case, you don’t need to provide an access token. The following code demonstrates how this request would look if you are using the cross-domain library and want to receive the OData representation of the lists as XML instead of JSON. See How to: Access SharePoint 2013 data from remote apps using the cross-domain library for more information about using the cross-domain library.

这是该文章的当前网址http://msdn.microsoft.com/en-us/library/fp179927.aspx

这应该是你的正确答案

这篇关于如何在 sharepoint 2013 中获得 oauth 访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆