我正在嘗試從 Microsoft Graph Explorer 檢索用戶正在關注的站點。
我發現這份檔案可以做到這一點:
如果您從任何其他介面(例如代碼)訪問Graph API,則需要手動形成請求標頭并包含您獲得的令牌。
如何獲取服務應用程式的令牌需要更多資訊,您可以從官方檔案中閱讀更多資訊
這是一個使用 Python 和 MSAL 以及構造的請求標頭的簡單示例。
app = msal.ConfidentialClientApplication(
client_id = client_id,
client_credential = client_secret,
authority = f"https://login.microsoftonline.com/{tenant_id}")
scopes = ["https://graph.microsoft.com/.default"]
token = None
token = app.acquire_token_for_client(scopes = scopes)
req_headers = {
"Authorization": "Bearer " token['access_token']
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/479385.html
下一篇:用戶管理后臺代碼,輕松復制實作
