Something wrong with OneDrive api
import msal
from office365.graph_client import GraphClient
def acquire_token_func():
"""
Acquire token via MSAL
"""
authority_url = 'https://login.microsoftonline.com/xxxx'
app = msal.ConfidentialClientApplication(
authority=authority_url,
client_id='xxxx',
client_credential='xxxxx'
)
token = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
return token
print(acquire_token_func())
tenant_name = "contoso.onmicrosoft.com"
client = GraphClient(acquire_token_func)
drives = client.drives.get().execute_query()
for drive in drives:
print("Drive url: {0}".format(drive.web_url))
I can get the token, but then something is wrong.
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/office365/runtime/client_request.py", line 94, in execute_query response.raise_for_status() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/drives
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/zhuhaoyumbp15/Desktop/UTS/OneDrive/main.py", line 22, in
I'm having the same issue. Eager to see if this gets resolved.
Greetings,
most likely application has not been configured properly.
A few things to verify:
-
for
List available drivesendpoint one of the following application permissions needs to be granted:Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All
JWT token for client credentials could also be verified in terms if it contains roles property by examining it, for instance, via jwt.io