gpt4 book ai didi

ajax获取对Office365 REST Api的请求失败CORS?

转载 作者:行者123 更新时间:2023-12-04 08:48:33 24 4
gpt4 key购买 nike

我正在尝试从本地服务器向 Office365 RESTful API 服务发出 ajax GET 请求,但遇到跨域 HTTPRequest 错误。以下是我的“get-files-at-root”尝试示例:

$.ajax({
url: 'https://[sharepoint_site]/_api/v1.0/me/files?access_token='+token,
type: 'get',
dataType: 'json',
success: function(data) {
if (success){
success(data);
}
},
error: error
})

我从服务器收到以下响应:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403.

我尝试将访问 token 作为 header 参数发送:
headers: {'Authorization': 'Bearer '+ token}

但这有相同的结果。

关于我做错了什么的任何想法?

(背景:我正在尝试在客户端上创建自己的 Office365“文件选择器”,因为我找不到提供此功能的 OneDrive Business 可用库。)

最佳答案

Office 365 文件 API 和 SharePoint REST 刚刚引入了对 CORS 的支持。

https://msdn.microsoft.com/en-us/office/office365/howto/create-web-apps-using-CORS-to-access-files-in-Office-365

你试图做的正是它是如何工作的。该服务将使用 Access-Control-Allow-Origin header 响应 OPTIONS 飞行前请求。

请求中的授权必须是 Azure Active Directory 颁发的 OAuth2 隐式授予访问 token 。

关于ajax获取对Office365 REST Api的请求失败CORS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28309771/

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