gpt4 book ai didi

javascript - 从单独的应用程序访问 Sharepoint Project Web 应用程序 REST

转载 作者:行者123 更新时间:2023-11-28 05:06:22 25 4
gpt4 key购买 nike

我需要连接到我们公司的 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();

我还尝试了几种不同的方法,全部使用不记名 token 。

问题是此代码适用于访问 https://<companySite>.sharepoint.com/sites/pwa/_api/web/lists但不适用于 https://<companySite>.sharepoint.com/sites/pwa/_api/ProjectData/Projects?$select=ProjectName

对于后者,它返回:

{"odata.error":{"code":"20010, Microsoft.ProjectServer.PJClientCallableException","message":{"lang":"en-US","value":"GeneralSecurityAccessDenied"}}} 

可能出现什么问题?

我知道我的 token 是正确的,因为它可用于访问 */web/lists 。我也知道该网址是正确的,因为我可以在浏览器中打开它(前提是我已登录到 sharepoint)

最佳答案

您需要使用 FormDigestValue。

对 .../_api/contextinfo 进行 GET 调用并存储“FormDigestValue”的值。然后,对于所有其他调用,添加 header X-RequestDigest: <FormDigestValue>

关于javascript - 从单独的应用程序访问 Sharepoint Project Web 应用程序 REST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41719686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com