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

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

问题描述

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

I have this site here: 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跨域库,则此请求看起来会略有不同。在这种情况下,您不需要提供访问令牌。以下代码演示了如果您使用跨域库并希望将列表的OData表示形式接收为XML而不是JSON,此请求将如何显示。有关使用跨域库的详细信息,请参阅如何:使用跨域库从远程应用程序访问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

This is currently the url to that article http://msdn.microsoft.com/en-us/library/fp179927.aspx

这应该是你的正确答案

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

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