简体   繁体   中英

Getting gibberish when trying to download file from sharepoint using microsoft graph api

I'm trying to download some excel file from our sharepoint. I'm following instructions from this resource: https://docs.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http

when I try to call the endpoint from Postman, I get some gibberish and a pretty long one. the tutorial says I'm supposed to get a 302 response but I get a 200 response.

I also have all the permission granted for read write for Site and Files.

from postman, I translate the code to python. here's my code. I get the same result on my python script:

url = "https://graph.microsoft.com/v1.0/drives/<our_drive_id>/items/<target_file_id>/content"

        payload={}
        headers = {
          'Content-Type': 'application/json',
          'SdkVersion': 'postman-graph/v1.0',
          'Authorization': f'Bearer {token}' # retrieved from an endpoint called prior
        }

        response = requests.request("GET", url, headers=headers, data=payload)

        print(response)

here is the response that I get: 在此处输入图像描述

I'm not really sure since I don't get an actionable error. Also the response that I get is different from the expected response stated in the tutorial.

The documentation says that the request returns a 302 Found response redirecting to a pre-authenticated download URL for the file.

Postman follows the Location header in the response and makes a redirect to URL and downloads the content.

If you disable Automatically follow redirects in Postman settings then the response will be 302 and Location header will contain a download link.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM