在本质上,注册的单租户Microsoft Entra ID应用程序:
Calendars.ReadWrite
API许可,并授予管理员同意,如下所示:
使用授权类型,授权_Code Flow需要用户交流。要获取
code
,我在浏览器中跑了以下
:
https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize?
client_id=<client_id>
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345
成功地创建
authorization_code
使用以下参数创建POST https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
client_id: <application-id>
client_secret: <client-secret>
scope: https://graph.microsoft.com/.default
grant_type: authorization_code
code: <authorization_code generated from browser>
redirect_uri: <REDIRECT_URI
,生成的访问令牌:
Create Event Graph API
response:
allowNewTimeProposals
,从而允许邀请人建议替代会议时间。需要设置
true
allowNewTimeProposals:false
POST https://graph.microsoft.com/v1.0/me/calendars/{id}/events
Content-type: application/json
Authorization: Bearer {token}
Body:
{
"subject": "Meet about next steps",
"body": {
"content": "Let's talk about some stuff",
"contentType": "HTML"
},
"start": {
"dateTime": "2025-03-11T14:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2025-03-11T15:00:00",
"timeZone": "Pacific Standard Time"
},
"location": {
"displayName": "Meet Online in Teams Meeting"
},
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness",
"attendees": [
{
"emailAddress": {
"address": "<[email protected]>",
"name": "<Attendee_Name>"
},
"type": "required"
}
],
"allowNewTimeProposals": false
}
指出,通过禁用提出的新时间功能,在Microsoft日历上成功创建了事件。
参考:
创建日历事件