首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UnableToDeserializePostBody在尝试创建与php Microsoft会晤的团队时

UnableToDeserializePostBody在尝试创建与php Microsoft会晤的团队时
EN

Stack Overflow用户
提问于 2022-07-14 10:51:29
回答 1查看 78关注 0票数 1

调用图API端点

代码语言:javascript
运行
复制
POST https://graph.microsoft.com/v1.0/me/events 

结果是一个400 Bad Request,响应如下:

代码语言:javascript
运行
复制
{
    "error": {
      "code":"UnableToDeserializePostBody",
      "message":"were unable to deserialize..."
    }
}

这是我的密码:

代码语言:javascript
运行
复制
$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();

“”“

其余的代码可以工作,我可以验证。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-14 10:59:19

message对象中删除$CreateMeetingBody对象,并仅保留其内容。

代码语言:javascript
运行
复制
$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体。

代码语言:javascript
运行
复制
{
  "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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72979298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档