2016-08-25 1 views
3

Microsoft API를 통해 onedrive 항목의 콘텐츠를 다운로드하려고합니다. 그러나 사용하는 방법에 관계없이 404 응답을 얻습니다. 여기에/파이썬에서 문제의 재현404 Microsoft Graph에서 OneDrive 콘텐츠 다운로드

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) 

를 요청하는 다음과 같은 출력 :

를 다운로드하도록되어 있지만, 즉시 404에있는 링크 결과 다음과 같은 그런 말을하는 것입니다
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: 
[] 

파일 바이트. 파이썬, bash/curl, 그리고 브라우저에서 이것을 재현했습니다. 아무도 내가 잘못하고있는 것을 지적하거나, 이것이 마이크로 소프트 그래프 API의 문제입니까?

편집 :/드라이브/상품/{아이템 ID}를 사용

I도 재생할 수 동일한 404/콘텐츠 끝점 here 설명했다. 이 엔드 포인트에 대한 요청으로 인해 302 리다이렉트 (문서에 설명 된대로)가 발생하며, 뒤이어서 위에서 설명한 것과 동일한 404 작동이 발생합니다.

EDIT2 : 여기

내가 마이크로 소프트의 측면에서 디버깅을 위해 유용 보았다 응답 헤더에서 찾을 수있는 모든 요청 식별자입니다.

항목 개체에 대한 200 요청의 경우 'request-id': 'adfa3492-4825-439d-8e59-022f32e78244', 'client-request-id': 'adfa3492-4825-439d-8e59-022f32e78244' '요청 - ID': '33e09e9d-b0c2-2000-133c-304585c15000', 'SPRequestGuid'다운로드 URL을 404 요청에 대한

'33e09e9d-b0c2-2000-133c-304585c15000을'

또한 404에서 반환 된 실제 HTML에는 상관 ID가 포함되어 있습니다. a8e09e9d-a0bb-2000-133b-ef6fc8ac7015

+1

응답 헤더에서 "request-id"를 제공 할 수 있습니까? – Brad

+0

해당 e04e9d9d-9070-2000-133b-ef376013cbdc – User1234567890

+0

죄송합니다. 위의 요청 ID는 404 응답을위한 것입니다. 초기 요청 ID가 객체에 도착하기를 원한다면 알려주십시오. – User1234567890

답변

3

파일 다운로드는 here과 같이 위임 권한 (예 : File.Read 범위)에서만 지원됩니다. 귀하의 요청은 응용 프로그램 Files.Read.All 및 Files.ReadWrite.All로되어 있습니다. 우리는 점진적으로 지원을 추가하고 있지만 아직 완전히 기능하지는 않으며 here으로 나열되어 있지 않습니다.

+0

그게 사실입니까? –

+0

아직 공개되지 않은 문제입니까? 이것이 언제 변경 될 예정인가? – jdave

0

item_id가 실제로 항목의 ID인지 확인할 수 있습니까? GET /v1.0/users//drive/items/에 의해 반환 된 컬렉션에서 작업하는 경우 컬렉션은 폴더 및 항목 메타 데이터의 배열을 반환합니다. 폴더에 대한 요청을 시도하면 설명 된대로 404가 표시됩니다. 그것이 내가 당신의 문제를 재현 할 수있는 유일한 방법입니다. 문제가 아닌 경우 요청/응답 추적을 제공해 오류 세부 정보를 볼 수 있습니다.

+0

안녕하세요, Michael, 답변 해 주셔서 감사합니다. 초기 호출이 "file"속성을 포함하는 json 객체를 반환하기 때문에 item_id가 파일의 ID임을 확신합니다. 문서에 따르면, 이것은 객체가 파일이라는 것을 의미합니다. 찾을 수있는 모든 요청 응답 추적 정보가 들어있는 "EDIT2"를 추가했습니다. 포함해야하는 다른 것이 있으면 알려주십시오. – User1234567890

+0

@ User1234567890 RequestIds를 사용하여 전화를 조회 할 수 없습니다. 첫 번째 전화를 할 수 있습니까? item_id를받는 곳? 요청 및 위생 처리 된 (그리고 간략하게 요약 된) 응답 본문을 보여주십시오. –

+0

안녕 마이클, 후속 조치 주셔서 감사합니다. 필자의 원래 질문에있는 코드, 특히 item_id를 사용하여 항목을 요청한 첫 번째 requests.get 호출을 다시 살펴보십시오. 이 호출에 대한 응답은 항목을 설명하는 본문이있는 200이며, 이것이 유효한 항목 ID임을 나타냅니다. 내 질문의 두 번째 코드 블록에서이 응답을 볼 수 있습니다. 내가 겪고있는 문제는이 항목 응답과 함께 제공된 downloadUrl이 파일의 바이트를 다운로드하는 대신 404로 해결된다는 것입니다. 잘못된 항목 ID로 인해 404가 발생하지 않습니다. – User1234567890

관련 문제