簡體   English   中英

嘗試使用 php Microsoft Graph Api 創建團隊會議時出現 UnableToDeserializePostBody

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM