404从Microsoft Graph下载OneDrive内容

用户1234567890

我正在尝试通过Microsoft API下载onedrive项的内容。但是,无论使用哪种方法,我都会得到404响应。这是python / requests中问题的再现

import requests
import json

root_url = "https://graph.microsoft.com"
base_path = "/v1.0/<tenant_id>/users/<principal_name>/drive/"

token = "ALONGTOKEN"

headers = {"Authorization": "Bearer %s" % token}

r = requests.get(root_url + base_path + "/root/children", headers=headers)
listing = json.loads(r.text)
target = listing["value"][0]
print("Target node:")
print(json.dumps(target))
print("Target node id:")
print(target["id"])

r = requests.get(root_url + base_path + "items/" + target["id"], headers=headers)
print("Target metadata:")
print(r.text)

resp = json.loads(r.text)
download_url = resp["@microsoft.graph.downloadUrl"]
print("Target download url:")
print(download_url)

r = requests.get(download_url, headers=headers)
print("Download response code:")
print(r.status_code)
print("Download response headers:")
print(r.headers)
print("Download response cookies:")
print(r.cookies)
print("Download response redirect history:")
print(r.history)

输出以下内容:

Target node:
{"parentReference": {"driveId": "drive_id", "path": "/drive/root:", "id": "parent_id"}, "cTag": "\"c:{tag},1\"", "lastModifiedDateTime": "2016-08-24T17:32:45Z", "name": "birds.png", "createdDateTime": "2016-08-24T17:32:45Z", "image": {}, "webUrl": "https://org-my.sharepoint.com/personal/principal_name/Documents/birds.png", "lastModifiedBy": {"user": {"displayName": "User Name", "id": "user_id"}}, "eTag": "\"{etag},1\"", "createdBy": {"user": {"displayName": "User Name", "id": "user_id"}}, "@microsoft.graph.downloadUrl": "https://org-my.sharepoint.com/personal/principal_name/_layouts/15/download.aspx?guestaccesstoken=access_token&docid=did&expiration=2016-09-01T17%3a12%3a14.000Z&userid=uid&authurl=True&NeverAuth=True", "file": {"hashes": {}}, "id": "01L4SXJGJ2LR2PGPKJMVGZPHIADCAYJEFE", "size": 34038}

Target node id:
01L4SXJGJ2LR2PGPKJMVGZPHIADCAYJEFE

Target metadata:
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('principal_name')/drive/items/$entity","@microsoft.graph.downloadUrl":"https://org-my.sharepoint.com/personal/principal_name/_layouts/15/download.aspx?guestaccesstoken=accesstoken&docid=docid&expiration=2016-09-01T17%3a12%3a15.000Z&userid=uid&authurl=True&NeverAuth=True","createdBy":{"user":{"id":"user_id","displayName":"User Name"}},"createdDateTime":"2016-08-24T17:32:45Z","eTag":"\"{etag},1\"","id":"01L4SXJGJ2LR2PGPKJMVGZPHIADCAYJEFE","lastModifiedBy":{"user":{"id":"user_id","displayName":"User Name"}},"lastModifiedDateTime":"2016-08-24T17:32:45Z","name":"birds.png","webUrl":"https://org-my.sharepoint.com/personal/principal_name/Documents/birds.png","cTag":"\"c:{ctag},1\"","file":{"hashes":{}},"image":{},"parentReference":{"driveId":"drive_id","id":"parent_id","path":"/drive/root:"},"size":34038}

Target download url:
https://org-my.sharepoint.com/personal/principal_name/_layouts/15/download.aspx?guestaccesstoken=accesstoken&docid=docid&expiration=2016-09-01T17%3a12%3a15.000Z&userid=uid&authurl=True&NeverAuth=True

Download response code:
404

Download response headers:
{'Content-Length': '13702', 'SPIisLatency': '4', 'X-Content-Type-Options': 'nosniff', 'X-AspNet-Version': '4.0.30319', 'request-id': '288b9f9d-c04a-2000-133b-ebab2f6f332b', 'Strict-Transport-Security': 'max-age=31536000', 'MicrosoftSharePointTeamServices': '16.0.0.5625', 'X-Powered-By': 'ASP.NET', 'SPRequestGuid': '288b9f9d-c04a-2000-133b-ebab2f6f332b', 'Server': 'Microsoft-IIS/8.5', 'X-MS-InvokeApp': '1; RequireReadOnly', 'X-SharePointHealthScore': '0', 'SPRequestDuration': '297', 'SharePointError': '0', 'Cache-Control': 'private', 'Date': 'Thu, 01 Sep 2016 16:12:14 GMT', 'P3P': 'CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"', 'Content-Type': 'text/html; charset=utf-8'}

Download response cookies:
<RequestsCookieJar[]>

Download response redirect history:
[]

也就是说,尽管应该下载文件字节,但是紧随链接之后的结果却是404。我已经在Java,Python,bash / curl和浏览器中复制了此内容。任何人都可以帮助指出我在做什么错,或者这是Microsoft graph API的问题?

编辑:

我还可以使用此处描述的/ drive / items / {item-id} / content端点来复制相同的404 对该端点的请求将导致302重定向(如文档中所述),当遵循该重定向时,将导致与上述相同的404行为。

编辑2:

这是我可以在响应标头中找到的所有请求ID,它们对于从Microsoft端进行调试似乎很有用。

对于商品对象上的200个请求:'request-id':'adfa3492-4825-439d-8e59-022f32e78244','client-request-id':'adfa3492-4825-439d-8e59-022f32e78244'

对于下载网址上的404请求:“ request-id”:“ 33e09e9d-b0c2-2000-133c-304585c15000”,“ SPRequestGuid”:“ 33e09e9d-b0c2-2000-133c-304585c15000”,

此外,从404返回的实际HTML包括相关性ID:a8e09e9d-a0bb-2000-133b-ef6fc8ac7015

马雷克·里查斯基(Marek Rycharski)

文件下载目前仅支持与委托权限(如File.Read范围)作为记录在这里您的请求是使用应用程序许可权Files.Read.All和Files.ReadWrite.All提出的,我们正在逐渐增加对它们的支持,但它们尚未完全起作用,因此未在此处列出

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Microsoft Graph SDK从OneDrive下载大文件

Microsoft Graph Explorer / Microsoft Teams - 404 响应

Microsoft Graph-OneDrive API-下载前转换为jpg

使用Microsoft Graph创建指向OneDrive文件的永久公共下载链接

无法下载Microsoft符号-404错误

通过 Microsoft GRAPH 的 OneDrive 通知

使用Microsoft Graph API下载Sharepoint文件不显示内容属性

Android上的Microsoft Graph,在检索文件时响应404

Graph API Onedrive approot 创建为“Microsoft Graph”

如何使用Microsoft Graph将大文件上传到OneDrive

Microsoft Graph。使用应用程序自己的身份访问OneDrive

OneDrive Microsoft Graph错误:令牌包含无效签名

使用访问令牌通过Microsoft Graph API与OneDrive进行交互

OneDrive 文件下载返回 95 字节内容

Microsoft Graph API-按文件路径获取文件-找不到404

如何使用Microsoft Graph获取关注的内容

cURL 命令下载包含 404 NOT FOUND 内容的文件

无法使用PHP的Microsoft Graph SDK下载文件

使用“ sourcedoc” ID从Microsoft Graph API下载SharePoint文件

尝试下载用户图像时出现Microsoft.Graph.ServiceException

使用Microsoft Graph Rest API从邮件下载附件

Microsoft Graph:通过Rest API下载文件

Microsoft Graph-.NET SDK-OneDrive大文件上传(大小大于4MB)

如何使用Microsoft Graph API在OneDrive中获取文件的临时(或永久)常规URL

无法使用Microsoft Graph以全局管理员身份查询用户的OneDrive业务文件

我可以使用 Microsoft 的 Graph API 发送 OneDrive 文件请求吗?

用于访问用户 OneDrive 的 Microsoft Graph API 代码库解决方案

OneDrive FB 使用 Microsoft Graph API Powershell 创建文件夹

如何在C#中使用Microsoft Graph Api上传到OneDrive