Graph API中User1访问共享邮箱Intake文件夹的403权限问题求助
解决方案:以User1身份通过Graph API访问共享邮箱的Intake文件夹
核心原因
你使用的/users/sharedmailbox@contoso.com/mailFolders端点需要应用级权限或委托级的Mail.ReadWrite.All权限,而当前仅授予User1委托级的Mail.ReadWrite权限,因此会返回403错误。但User1已拥有共享邮箱的完全访问权限,只需通过/me路径即可访问该共享邮箱。
正确的访问方式
步骤1:获取共享邮箱的根文件夹ID(可选,可直接用邮箱地址访问)
发送GET请求到:
https://graph.microsoft.com/v1.0/me/mailFolders
在返回结果中找到displayName为sharedmailbox@contoso.com的文件夹,记录其id字段值。
步骤2:访问Intake文件夹
使用以下任一API端点:
- 方式一(直接用邮箱地址):
https://graph.microsoft.com/v1.0/me/mailFolders('sharedmailbox@contoso.com')/childFolders('Intake')
- 方式二(用共享邮箱根文件夹ID):
https://graph.microsoft.com/v1.0/me/mailFolders/{共享邮箱根文件夹ID}/childFolders('Intake')
修改后的Python测试代码
import requests # Define the base API URL, API version, and endpoint base_api = 'https://graph.microsoft.com' api_version = 'v1.0' endpoint_me = '/me/mailFolders' # 使用正确的共享邮箱Intake文件夹端点 endpoint_shared_intake = '/me/mailFolders(\'sharedmailbox@contoso.com\')/childFolders(\'Intake\')' # Define the access token (替换为实际的token) token = 'TOKEN' # Construct the URLs url_me = f'{base_api}/{api_version}{endpoint_me}' url_shared_intake = f'{base_api}/{api_version}{endpoint_shared_intake}' # Define the headers headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json' } # Send requests response_me = requests.get(url_me, headers=headers) response_shared_intake = requests.get(url_shared_intake, headers=headers) print(response_me.status_code) print(response_shared_intake.status_code) # 可选:打印返回内容 # print(response_shared_intake.json())
权限说明
- 你当前配置的委托级Mail.ReadWrite权限已足够,无需额外申请更高权限。
- 若使用
/users路径访问其他用户邮箱,需申请委托级的Mail.ReadWrite.All权限,但这会允许访问所有用户邮箱,不符合你的需求,因此不建议使用。
内容的提问来源于stack exchange,提问作者Alex You
相关产品推荐
相关产品推荐

