You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Microsoft Graph API提取Booking数据遇500及401错误排查

Microsoft Graph API调用Bookings列表端点返回500错误排查

我尝试通过应用权限自动化调用Microsoft Graph API提取Microsoft Bookings数据,AAD应用已配置Bookings.Read.All权限。

获取Access Token的代码:

import msal

client_id = 'x'
client_secret = 'x'
authority = 'https://login.microsoftonline.com/x'
scope = ['https://graph.microsoft.com/.default']

client = msal.ConfidentialClientApplication(client_id, authority=authority, client_credential=client_secret)

token_result = client.acquire_token_silent(scope, account=None)

if token_result:
  access_token = 'Bearer ' + token_result['access_token']
  print('Access token was loaded from cache')

if not token_result:
  token_result = client.acquire_token_for_client(scopes=scope)
  access_token = 'Bearer ' + token_result['access_token']
  print('New access token was acquired from Azure AD')

print(access_token)

调用Graph API的代码:

import requests

url = 'https://graph.microsoft.com/v1.0/solutions/bookingBusinesses'
headers = {
  'Authorization': access_token
}

graph_result = requests.get(url=url, headers=headers)

print(graph_result)

调用上述代码返回500错误,提示“An error has occurred”。

更新信息

  • 更新1:调用指定单个Booking Business的Get端点(如/solutions/bookingBusinesses/CalendarTest@company.com)可正常返回数据,说明Python代码及Access Token无问题。
  • 更新2:AAD应用权限配置已添加Bookings.Read.All应用权限并完成管理员同意。
  • 更新3:尝试用其他方式生成的Authorization Code手动转换为Access Token后,调用API返回401错误,错误信息如下:
{"error":{"code":"","message":"此请求已被拒绝授权。","innerError":{"date":"2023-04-12T10:35:49","request-id":"b8904cad-c994-4a91-bd61-6bfbcb87bbaa","client-request-id":"b8904cad-c994-4a91-bd61-6bfbcb87bbaa"}}}

请问问题出在哪里?

内容的提问来源于stack exchange,提问作者Dusty Bin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 22:45:37