Я пытаюсь подключиться к OneDrive для чтения файлов, общих с моей учетной записью, но я использую Client Secret, чтобы можно было запланировать выполнение кода. Я установил разрешения для приложения, которое я использую для подключения к API, как на рисунке (разрешения API), но я получаю ошибку «недостаточные привилегии для завершения операции».
Я довольно промежуточный пользователь Python, так что нужна помощь в этом.from msal import ConfidentialClientApplication
import requests
# App credentials
CLIENT_ID = "your_client_id" # Application (Client) ID from Azure
CLIENT_SECRET = "your_client_secret" # Generated client secret
TENANT_ID = "your_tenant_id" # Directory (Tenant) ID from Azure
# MSAL application
app = ConfidentialClientApplication(
client_id=CLIENT_ID,
client_credential=CLIENT_SECRET,
authority=f"https://login.microsoftonline.com/{TENANT_ID}",
)
# Get a token for Microsoft Graph
SCOPES = ["https://graph.microsoft.com/.default"] # Required for Client Credentials Flow
token_response = app.acquire_token_for_client(scopes=SCOPES)
# Check token response
if "access_token" in token_response:
access_token = token_response["access_token"]
print("Access token acquired.")
# Use the token to call Microsoft Graph
GRAPH_API_URL = "https://graph.microsoft.com/v1.0/users"
headers = {"Authorization": f"Bearer {access_token}"}
response = requests.get(GRAPH_API_URL, headers=headers)
if response.status_code == 200:
print("Graph API response:", response.json())
else:
print("Graph API error:", response.json())
else:
print("Failed to acquire token:", token_response.get("error_description")
Подробнее здесь: https://stackoverflow.com/questions/793 ... ent-secret
Подключитесь к OneDrive с помощью Python (MSAL) и Client Secret ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение