Javascript 从单独的应用程序访问Sharepoint Project web应用程序REST

Javascript 从单独的应用程序访问Sharepoint Project web应用程序REST,javascript,rest,sharepoint,oauth-2.0,Javascript,Rest,Sharepoint,Oauth 2.0,我需要连接到我们公司的PWA。这是我正在使用的代码: // var endpointUrl = 'https://<companySite>.sharepoint.com/sites/pwa/_api/web/lists'; var endpointUrl = 'https://<companySite>.sharepoint.com/sites/pwa/_api/ProjectData/Projects?$select=ProjectName'; var xhr = n

我需要连接到我们公司的PWA。这是我正在使用的代码:

// var endpointUrl = 'https://<companySite>.sharepoint.com/sites/pwa/_api/web/lists';
var endpointUrl = 'https://<companySite>.sharepoint.com/sites/pwa/_api/ProjectData/Projects?$select=ProjectName';
var xhr = new XMLHttpRequest();
xhr.open("GET", endpointUrl);

// The APIs require an OAuth access token in the Authorization header, formatted like this: 'Authorization: Bearer <token>'. 
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.setRequestHeader("Accept", "application/json");

$("#header").html("Requesting: " + endpointUrl);

// Process the response from the API.  
xhr.onload = function () {
  if (xhr.status == 200) {
     var formattedResponse = JSON.stringify(JSON.parse(xhr.response), undefined, 2);
           $("#results").html("<pre>" + formattedResponse + "</pre>");
         } else {
           $("#results").html("HTTP " + xhr.status + "<br>" + xhr.response);
         }
     }

   // Make request.
   xhr.send();
可能的问题是什么


我知道我的令牌是正确的,因为它用于访问
*/web/lists
。我还知道url是正确的,因为我可以在浏览器中打开它(前提是我已登录sharepoint)

您需要使用FormDigestValue


对…/_api/contextinfo进行GET调用,并存储“FormDigestValue”的值。然后,对于所有其他调用,添加一个标题
X-RequestDigest:

,您需要使用FormDigestValue


对…/_api/contextinfo进行GET调用,并存储“FormDigestValue”的值。然后,对于所有其他调用,添加具有相同问题的
X-RequestDigest:

标题。按照您的建议,我可以通过调用_api/contextinfo获得FormDigestValue,但在执行get to _api/ProjectData/Projects时,将其用作X-RequestDigest头仍然以“拒绝访问”结束。还有其他想法吗?你需要用一篇帖子,而不是一篇文章。仍然得到403分。如果你能提出问题所在。谢谢有同样的问题。按照您的建议,我可以通过调用_api/contextinfo获得FormDigestValue,但在执行get to _api/ProjectData/Projects时,将其用作X-RequestDigest头仍然以“拒绝访问”结束。还有其他想法吗?你需要用一篇帖子,而不是一篇文章。仍然得到403分。如果你能提出问题所在。谢谢-
{"odata.error":{"code":"20010, Microsoft.ProjectServer.PJClientCallableException","message":{"lang":"en-US","value":"GeneralSecurityAccessDenied"}}}