前言
在 Teams App 代替使用者建立線上會議,讓該使用者為會議主持人 可以透過 App 快速建立 線上會議 。
但這樣只是建立線上會議,跟 Calendar 無關,而且還要透過 Access Policy 去設定。
所以更方便的做法就是在 Calendar 上建立 會議 ,並設定它是線上會議,這樣就不用特別去設定 Access Policy。
實作
因為要建立 Calendar ,所以 App 需要的 Application permissions 為 Calendars.ReadWrite,而原本需要的 OnlineMeetings.ReadWrite.All
權限則可以 Revoke admin consent 後,再 Remove premission。
將 App 從 Access Policy 中移除,移除套用 Access Policy 的使用者, 並將 Access Policy 移除。1
2
3
4
5
6
7
8# 移除套用 Access Policy 的使用者
Get-CsOnlineUser | Grant-CsApplicationAccessPolicy -PolicyName $Null
# 將 App 從 Access Policy 中移除
Set-CsApplicationAccessPolicy -Identity "teams-meetings-policy" -AppIds @{Remove="要移的Application (client) ID"}
#將 Access Policy 移除
Remove-CsApplicationAccessPolicy -Identity "teams-meetings-policy"
加入 Calendars.ReadWrite 權限後,一樣需要 Grant admin consent。
再來就是取得 App 的 Token
依 Get access without a user 的 4. Get an access token ,
依 Application (client) ID 及 Client secrets,Scope 給 https://graph.microsoft.com/.default 來取回 Token。
在 Calendar 上建立 會議 ,並設定它是線上會議
依 Enable an event as an online meeting in an Outlook calendar,拿上述取得的 App Token ,使用 https://graph.microsoft.com/v1.0/users/{user Object Id}/events
,並給會議的資訊,例如,1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30{
"subject": "線上會議測試",
"body": {
"contentType": "HTML",
"content": "<h3>hello events</h3>線上會議測試--- 有時間嗎?"
},
"start": {
"dateTime": "2022-05-03T18:00:00.0000000+08:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2022-05-03T18:30:00.0000000+08:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"666 會議室"
},
"attendees": [
{
"emailAddress": {
"address":"rainmaker@rm.com.tw",
"name": "rainmaker"
},
"type": "required"
}
],
"allowNewTimeProposals": true,
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"
}
這樣就會在行事曆中顯示該線上會議,

參考資源
Enable an event as an online meeting in an Outlook calendar
Grant-CsApplicationAccessPolicy