我尝试从localhost中部署的应用程序中使用sharepoint rest API . sharepoint站点在Sharepoint 2013在线托管 .
为此,我使用javascrpt跨域库 . 我在这里得到一个例子https://github.com/OfficeDev/SharePoint-Add-in-REST-OData-CrossDomain .
我的应用程序是一个完整的静态网站,我没有VS,所以我试图弄清楚添加授权 . 我转到我网站的 _layouts/15/appinv.aspx
页面,授权第三方申请:
-
app domain:localhost:8080
-
重定向网址:http://localhost:8080(无意义?)
-
权限请求XML:
<AppPrincipal><RemoteWebApplication ClientId="*" /></AppPrincipal>
当我转到我的应用程序时,我已通过我的帐户进行身份验证:cookie中填充了 FedAuth
和 rtFa
中的令牌
我想现在应该使用API应该足够了:
var executor = new SP.RequestExecutor(addinweburl);
executor.executeAsync(
{
url:
addinweburl + "/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents')"
,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function(e) {
alert('success');
},
error: function(e, c, d) {
alert('fail');
}
}
);
调用错误处理程序并发送1007错误代码 . 这很奇怪,因为当代码太重要时使用此代码 .
任何帮助表示赞赏 .
1 回答
如果应用程序未部署在同一个sharepoint站点域上,则无法使用该库...
我回退到OAuth协议以验证我的客户端 . 以下文档是了解如何获取访问令牌的关键:https://github.com/wearearchitect/sharepoint-oauth-app-client/blob/master/docs/Credentials.md