[Python] How do I use Microsoft's Pyton SDK for Graph API to download or list files from...

Discussão em 'Python' iniciado por Stack, Agosto 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently trying to use Python to download files from SharePoint (eventually want to get them to Azure blob storage). I have not been able to figure out how to use Microsoft's SDK to do authenticate. I was able to successfully download/list files by using the azure.identity package to get a token and constructing the get request myself using the requests package. I would like to know how to use Microsofts SDK to do something similar to below, if possible using InteractiveBrowserCredential without having to use an Azure App Registration. I have one, but I am currently waiting on it to be assigned the correct API permissions (Sites.Selected I believe).

    from azure.identity import InteractiveBrowserCredential
    import requests
    import json

    tenant_id = 'my_tenant_id'

    credential = InteractiveBrowserCredential(tenant_id=tenant_id)
    token = credential.get_token('https://graph.microsoft.com/.default', tenant_id=tenant_id).token

    response = requests.get(url="https://graph.microsoft.com/.default" +
    "/sites/mycompany.sharepoint.com,xxx,xxx/" +
    "drives/xxx/root:/Home/Files:/children",
    headers={'Authorization': 'Bearer ' + token,
    'Accept': 'application/json'
    })

    response_dict = json.loads(response.text)
    pretty = json.dumps(json.loads(response.text), indent=4)
    print(pretty)

    Continue reading...

Compartilhe esta Página