gpt4 book ai didi

sharepoint - 从 SharePoint 下载 MS Graph API 文件

转载 作者:行者123 更新时间:2023-12-02 00:12:58 25 4
gpt4 key购买 nike

我正在尝试使用图形 API 从表单库下载 XML 文件,但它不起作用。我正在引用文档 here我认为这告诉我正确的语法是 GET/sites/{siteId}/drive/items/{item-id}/content。但是,当我使用 Graph Explorer 使用该语法时,它会显示 404 未找到文件。接下来我尝试了语法 GET/drives/{drive-id}/items/{item-id}/content 并返回状态代码 0 但消息正文只是说 {"isTrusted": true }.我应该注意,如果我删除 URL 上的最后一个参数并使用 GET/drives/{drive-id}/items/{item-id} 语法,它确实会带回文件信息。

语法有问题吗?这也许不是您可以用表单库中的 XML 文件做的事情吗?这可能是 Graph Explorer 的限制吗?

最佳答案

当您点击 /drives/{drive-id}/items/{item-id}/content 端点时,Microsoft Graph 响应 302 重定向,浏览器因 CORS 策略而拒绝该重定向。

这是来自 Downloading OneDrive files in JavaScript apps section 的解释:

To download files from OneDrive in a JavaScript app you cannot use the /content API, since this responds with a 302 redirect. A 302 redirect is explicitly prohibited when a CORS preflight is required, such as when providing the Authorization header.

Instead, your app needs to select the @microsoft.graph.downloadUrl property, which returns the same URL that /content would have redirected to. This URL can then be requested directly using XMLHttpRequest. Because these URLs are pre-authenticated they can be retrieved without a CORS preflight request.

要在 Graph Explorer 中下载文件,首先发出一个包含 @microsoft.graph.downloadUrl 属性的请求:

GET /drive/items/{item-id}?select=@microsoft.graph.downloadUrl

然后可以通过标记对 @microsoft.graph.downloadUrl 属性中提供的 Url 的另一个请求来下载文件

关于sharepoint - 从 SharePoint 下载 MS Graph API 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58228140/

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