![](/img/trans.png)
[英]microsoft graph api to create online meeting programmatically but facing 403 error
[英]UnableToDeserializePostBody when trying to create a teams meeting with php Microsoft Graph Api
調用 Graph API 端點
POST https://graph.microsoft.com/v1.0/me/events
導致400 Bad Request
響應:
{
"error": {
"code":"UnableToDeserializePostBody",
"message":"were unable to deserialize..."
}
}
這是我的代碼:
$token = GraphHelper::getUserToken();
GraphHelper::$userClient->setAccessToken($token);
$CreateMeetingBody =
array(
'message' => array (
'subject' => 'Test afspraak Marloes',
'body' => array (
'content' => 'Does morning work for you?',
'contentType' => 'HTML'
),
'start' => array (
'dateTime' => '2022-07-17T18:00:00',
'timeZone' => 'Europe/Paris'
),
'end' => array (
'dateTime' => '2022-07-17T19:00:00',
'timeZone' => 'Europe/Paris'
),
'location' => array (
'displayName' => 'Microsoft Teams',
),
'attendees' => array (
array (
'emailAddress' => array (
'address' => 'stijnd0413@icloud.com',
'name' => 'Stijn Deckers'
),
'type' => 'required'
)
),
'allowNewTimeProposals' => false,
'isOnlineMeeting' => true,
)
);
$headers = [
'Content-Type' => 'application/json',
];
header('Content-Type: application/json; charset=utf-8');
$CreateMeetingJSON = json_encode($CreateMeetingBody);
GraphHelper::$userClient->createRequest('POST', '/me/events')
->attachBody($CreateMeetingJSON)
->addHeaders(['Content-Type' => 'application/json',])
->execute();
'''
其余代碼有效,我能夠進行身份驗證。
從$CreateMeetingBody
中刪除message
對象並僅保留其內容。
$CreateMeetingBody =
array(
'subject' => 'Test afspraak Marloes',
'body' => array (
'content' => 'Does morning work for you?',
'contentType' => 'HTML'
),
'start' => array (
'dateTime' => '2022-07-17T18:00:00',
'timeZone' => 'Europe/Paris'
),
'end' => array (
'dateTime' => '2022-07-17T19:00:00',
'timeZone' => 'Europe/Paris'
),
'location' => array (
'displayName' => 'Microsoft Teams',
),
'attendees' => array (
array (
'emailAddress' => array (
'address' => 'stijnd0413@icloud.com',
'name' => 'Stijn Deckers'
),
'type' => 'required'
)
),
'allowNewTimeProposals' => false,
'isOnlineMeeting' => true
);
現在json_encode($CreateMeetingBody)
將生成正確的 json 正文
{
"subject": "Test afspraak Marloes",
"body": {
"content": "Does morning work for you?",
"contentType": "HTML"
},
"start": {
"dateTime": "2022-07-17T18:00:00",
"timeZone": "Europe/Paris"
},
"end": {
"dateTime": "2022-07-17T19:00:00",
"timeZone": "Europe/Paris"
},
"location": {
"displayName": "Microsoft Teams"
},
"attendees": [
{
"emailAddress": {
"address": "stijnd0413@icloud.com",
"name": "Stijn Deckers"
},
"type": "required"
}
],
"allowNewTimeProposals": false,
"isOnlineMeeting": true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.