首页 文章

使用sharepoint跨域javascript库从localhost使用REST API

提问于
浏览
0

我尝试从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中填充了 FedAuthrtFa 中的令牌

我想现在应该使用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 回答

相关问题