我正在使用
這是我的 Graph API 呼叫,它僅適用于從 graph-explorer 復制的不記名令牌
def recreate_graph_request1(bearer = None):
'''
I went to https://developer.microsoft.com/en-us/graph/graph-explorer
and picked a request. Outlook>GET emails from a user
at first response was for some generic user, but I logged in using my account and it actually worked.
Then I used my old copy curl as bash trick to make it python
:return:
'''
url = "https://graph.microsoft.com/v1.0/me/messages?$filter=(from/emailAddress/address) eq '[email protected]'"
payload = {}
headers = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Authorization': bearer,
'Connection': 'keep-alive',
'Origin': 'https://developer.microsoft.com',
'Referer': 'https://developer.microsoft.com/',
'SdkVersion': 'GraphExplorer/4.0, graph-js/3.0.2 (featureUsage=6)',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-site',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
'client-request-id': 'n0t_th3_s4m3_4s_1n_P05tm4n',
'sec-ch-ua': '"Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"'
}
response = requests.request("GET", url, headers=headers, data=payload)
return response
token_from_ms_auth = 'eyCOPIED_FROM_POSTMAN....'
bearer_from_ms_auth = 'Bearer ' token_from_ms_auth
print(recreate_graph_request1(bearer_from_ms_auth).text)
TBH,我并不太樂觀地認為任何不記名令牌都會起作用,即使它與我的租戶有某種關聯 - 但我希望它會,由此產生的失望促使我向宇宙尋求幫助。我不明白這些曲折的流程,看別人的答案只會讓我更加困惑。我希望有人可以幫助我弄清楚這種情況。
uj5u.com熱心網友回復:
訪問令牌是短暫的。過期后重繪 它們以繼續訪問資源。

請參考本檔案:https ://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#refresh-the-access-token
希望這可以幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/520701.html
