我正在尝试使用 MS Graph API(我是新手)编写 Powershell 脚本,将事件从私有(private)组日历复制到公共(public)强>组日历。
到目前为止,我已经成功使用此调用获取私有(private)组:
$api = "https://graph.microsoft.com/v1.0/groups"
$groups = $null
try { $groups = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)" } -Uri $api -Method "GET" -ContentType "application/json" }
catch { Write-host -Foreground Red $_}
$calendar_group = $groups.value | ? -Property mailNickname -eq $pvt_group
但是,当我尝试向前移动并获取该组的事件时,我会因 403 错误而被退回。
我正在尝试的调用是:
$api = "https://graph.microsoft.com/v1.0/groups/$group_ID/calendar/events"
Write-Host $api -Fore Green
$events = $null
try { $events = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)" } -Uri $api -Method "GET" -ContentType "application/json" }
catch { Write-host -Foreground Red $_}
或者:
$api = "https://graph.microsoft.com/v1.0/groups/$group_ID/events"
Write-Host $api -Fore Green
$events = $null
try { $events = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)" } -Uri $api -Method "GET" -ContentType "application/json" }
catch { Write-host -Foreground Red $_}
两者都因同一错误而失败。 注意:第一次调用时 $group_ID 变量的值是正确的。
我已在 Azure 上注册了该应用并具有以下权限:
- 日历.读取委托(delegate)
- 日历.读取.共享委托(delegate)
- Calendars.ReadWrite 委托(delegate)
- Calendars.ReadWrite.Shared 委托(delegate)
- Directory.AccessAsUser.All 已委派
- Directory.Read.All 已委派
- Directory.Read.All 应用程序
- Directory.ReadWrite.All 已委派
- Directory.ReadWrite.All 应用程序
- Group.Read.All 已委派
- Group.Read.All 应用程序
- Group.ReadWrite.All 已委派
- Group.ReadWrite.All 应用程序
- GroupMember.Read.All 已委派
- GroupMember.Read.All 应用程序
- User.Read 已委托(delegate)
有人知道我做错了什么吗? 非常感谢。
最佳答案
您使用的访问 token 是应用程序访问 token (权限在角色
部分下定义)。如果使用用户访问 token ,您将在 de scp
部分下看到权限。
在 Microsoft 文档 ( here ) 中,不幸的是,应用程序访问 token 不支持调用/calendar/events。
如果您将帐户分配给群组管理员
角色,您将隐式获得Group.Read.All
权限。然后使用您帐户中的访问 token 调用端点,不会出现任何问题(因为您已经在应用程序注册中授予了委派所需的权限)。
关于azure - Microsoft Graph API 获取组事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68726496/