Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint 404从Microsoft Graph下载OneDrive内容_Sharepoint_Office365_Onedrive_Microsoft Graph Api - Fatal编程技术网

Sharepoint 404从Microsoft Graph下载OneDrive内容

Sharepoint 404从Microsoft Graph下载OneDrive内容,sharepoint,office365,onedrive,microsoft-graph-api,Sharepoint,Office365,Onedrive,Microsoft Graph Api,我正在尝试通过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

我正在尝试通过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)
导入请求
导入json
根目录url=”https://graph.microsoft.com"
基本路径=“/v1.0//users//drive/”
token=“ALONGTOKEN”
标头={“授权”:“承载%s”%token}
r=requests.get(root\u url+base\u path+“/root/children”,headers=headers)
listing=json.loads(r.text)
目标=清单[“值”][0]
打印(“目标节点:”)
打印(json.dumps(目标))
打印(“目标节点id:”)
打印(目标[“id”])
r=requests.get(root\u url+base\u path+“items/”+target[“id”],headers=headers)
打印(“目标元数据:”)
打印(右文本)
resp=json.loads(r.text)
下载\u url=resp[“@microsoft.graph.downloadUrl”]
打印(“目标下载url:”)
打印(下载url)
r=requests.get(下载url,headers=headers)
打印(“下载响应代码:”)
打印(r.状态\ U代码)
打印(“下载响应标题:”)
打印(右标题)
打印(“下载响应cookies:”)
打印(r.cookies)
打印(“下载响应重定向历史记录:”)
印刷(r.历史)
产出如下:

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:
[]
目标节点:
{“parentReference”:{“driveId”:“drive\u id”,“path”:“/drive/root:”,“id”:“parent\u 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”:{“用户”:{“displayName”:“用户名”,“id”:“用户id”},“eTag”:“\”{eTag},1\”,“createdBy”:“{“用户”:“{”displayName”:“用户名”,“id”:“用户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,“文件”:{“哈希”:{},“id”:“01L4SXJGJ2LR2PGPKJMVGZPHIADCAYJEFE”,“大小”:34038}
目标节点id:
01L4SXJGJ2LR2PGPKJMVGZPHIADCAYJEFE
目标元数据:
{“@odata.context”:https://graph.microsoft.com/v1.0/$metadata#users(‘主体名称’)/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\u id”,“displayName:“user Name”}}”,createdDateTime:“2016-08-24T17:32:45Z”,“eTag:“{eTag},1\”,“id:“01L4SXJGJ2LR2PGPKJMVGZPHIADCAYJEFE”,“lastModifiedBy:{”user:“{”id:“user\u id”,“displayName:“user Name”}}”,lastModifiedDateTime:“2016-08-24T17:32:45Z:“URL:“birds.png”:”https://org-my.sharepoint.com/personal/principal_name/Documents/birds.png“,“cTag”:“\“c:{cTag},1\”,“文件”:{“哈希”:{},,“图像”:{},,“父引用”:{“驱动器id”:“驱动器id”,“id”:“父级id”,“路径”:“/drive/root:”,“大小”:34038}”
目标下载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
下载响应代码:
404
下载响应标题:
{'Content-Length':'13702','SPIisLatency':'4','X-Content-Type-Options':'nosniff','X-AspNet-Version':'4.0.30319','request id':'288b9f9d-c04a-2000-133b-ebab2f6f332b','smocofSharePointTeamServices':'16.0.0.5625','X-Powered-By':'ASP.NET','SPRequestGuid':'B9F9D-288C04A-2000-133B2F6F'332b、“服务器”:“Microsoft IIS/8.5”、“X-MS-InvokeApp”:“1;RequireReadOnly”、“X-SharePointHealthScore”:“0”、“SPRequestDuration”:“297”、“SharePointError”:“0”、“缓存控制”:“private”、“Date”:“Thu,2016年9月1日16:12:14 GMT”、“P3P”:“CP=”所有IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSA TAI TELo我们的SAMo CNT COM INT NAV only PHY-PUR UNI“,”内容类型“:”text/html;charset=utf-8'}
下载响应cookie:
下载响应重定向历史记录:
[]
也就是说,紧接着链接会产生一个404,尽管它应该下载文件字节。我已经在java、python、bash/curl和浏览器中复制了这一点。谁能帮我指出我做错了什么,或者这是microsoft graph api的问题吗

编辑:

我还可以使用所描述的/drive/items/{item id}/content端点复制相同的404。对该端点的请求会导致302重定向(如文档中所述),随后会导致与上述相同的404行为

编辑2:

下面是我在响应头中找到的所有请求ID,这些ID对于从Microsoft方面进行调试非常有用

对于项对象上的200请求:“请求id”:“adfa3492-4825-439d-8e59-022f32e78244”,“客户端请求id”:“adfa3492-4825-439d-8e59-022f32e78244”

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


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

您可以检查项目ID是否实际上是项目的ID吗?如果正在处理GET/v1.0/users//drive/items/返回的集合,则该集合将返回文件夹和项目元数据数组。如果您尝试对文件夹执行请求,您将获得404,如您所述。这是我能重新解释你的问题的唯一方法。如果这不是问题所在,请提供请求/响应跟踪,以便我们可以查看错误详细信息

文件下载目前仅支持授权的权限(如File.Read scope),如文件所述。您的请求是通过应用程序权限Files.Read.All和Files.ReadWrite.All发出的,我们正在逐步增加对它们的支持,但它们是