使用 sharepoint 跨域 javascript 库从 localhost 使用 REST API [英] Use sharepoint cross-domain javascript library to consume REST API from localhost

查看:72
本文介绍了使用 sharepoint 跨域 javascript 库从 localhost 使用 REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从部署在 localhost 中的应用程序使用 sharepoint rest API.Sharepoint 网站托管在 Sharepoint 2013 在线版中.

I try to consume the sharepoint rest API from an application deployed in localhost. The sharepoint site is hosted in Sharepoint 2013 online.

为此,我使用了 javascrpt 跨域库.我在这里得到一个例子 https://github.com/OfficeDev/SharePoint-Add-in-REST-OData-CrossDomain.

For that purpose I use the javascrpt cross domain library. I get an example here https://github.com/OfficeDev/SharePoint-Add-in-REST-OData-CrossDomain.

我的应用程序是一个完整的静态网站,我没有 VS,所以我试图找出 Add In 授权.我去我网站的_layouts/15/appinv.aspx页面给第三方应用授权:

My application is a full static website and I don't have VS, so I tried to figure out the Add In authorization. I go to the _layouts/15/appinv.aspx page of my site to give the authorization of third party application:

  • 应用域:本地主机:8080
  • 重定向网址:http://localhost:8080(毫无意义?)
  • 权限请求 XML:<AppPrincipal><RemoteWebApplication ClientId="*"/></AppPrincipal>
  • app domain: localhost:8080
  • redirect url: http://localhost:8080 (pointless?)
  • permission request XML: <AppPrincipal><RemoteWebApplication ClientId="*" /></AppPrincipal>

当我访问我的应用程序时,我使用我的帐户进行身份验证:cookie 填充了 FedAuthrtFa

When I go to my application, I'm authenticated with my account: the cookie is populated with the token in FedAuth and rtFa

我认为现在使用 API 应该足够了:

I'm supposing that it should be enough to now consume the 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 错误代码.这很奇怪,因为当大小太重要时使用此代码.

The error handler is called and the 1007 error code is sent. This is quite weird since this code is used when size is too important.

感谢任何帮助.

推荐答案

如果应用程序未部署在同一个 sharepoint 站点域中,则无法使用该库...

The library can't be used if the application is not deployed on the same sharepoint site domain...

我回退到 OAuth 协议以验证我的客户端.以下文档是了解如何获取访问令牌的关键:https://github.com/wearearchitect/sharepoint-oauth-app-client/blob/master/docs/Credentials.md

I fallback to OAuth protocol in order to authenticate my client. The following documentation was key to understand how to obtain an access token: https://github.com/wearearchitect/sharepoint-oauth-app-client/blob/master/docs/Credentials.md

这篇关于使用 sharepoint 跨域 javascript 库从 localhost 使用 REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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