使用Microsoft图形创建事件时出错

时间:2017-05-29 04:35:59

标签: events graph calendar composer-php microsoft-graph

$p=array(
        'subject'=>'Registrado desde iSchool',
        'body'=>array(
                    'contentType'=>'HTML',
                    'content'=>'Evento de prueba',                
                ),
        'start'=>array(
                    'dateTime'=>'2017-05-28T12:00:00',
                    'timeZone'=>'Pacific Standard Time'
                ),
        'end'=>array(
                    'dateTime'=>'2017-05-28T17:00:00',
                    'timeZone'=>'Pacific Standard Time'
                ),
        'location'=>array('displayName'=>'Mi casa'),
        'attendees'=>array(
                        'emailAddress'=>array('address'=>'email', 'name'=>'name'),
                        'type'=>'required'
                    ),            
    );
    $this->crear('calendars/'.$this->mg_model->idCalendarioUsuario().'/events', $p); 

此功能“$ this-> mg_model-> idCalendarioUsuario()”返回日历ID

public function crear($objeto, $datos){
    //$this->graph->setApiVersion("beta");
    $r = $this->graph->createRequest("POST", "/me/$objeto")      
        //->addHeaders(array("Content-Type" => "application/json"))    
        ->attachBody($datos)
        ->setReturnType(Event::class)    
        ->execute();
} 

Error: 400 Bad Request` response: { "error": { "code": "BadRequest", "message": "Property attendees in payload has a value that does not matc (truncated...)     

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您示例的JSON有效内容应如下所示:

{
    "subject": "Registrado desde iSchool",
    "body": {
        "contentType": "HTML",
        "content": "Evento de prueba"
    },
    "start": {
        "dateTime": "2017-05-28T12:00:00",
        "timeZone": "Pacific Standard Time"
    },
    "end": {
        "dateTime": "2017-05-28T17:00:00",
        "timeZone": "Pacific Standard Time"
    },
    "location": {
        "displayName": "Mi casa"
    },
    "attendees": [{
        "emailAddress": {
            "address": "email",
            "name": "name"
        },
        "type": "required"
    }]
}

然而,您的与会者集合将呈现为对象而非数组。它将您的与会者呈现为对象而不是数组。这可能是有效载荷错误的原因。

"attendees": {
    "emailAddress": {
        "address": "email",
        "name": "name"
    },
    "type": "required"
}

请注意,我不是PHP专家,因此我的代码可能相当不优雅。也就是说,我相信你可以通过将其包装成一个额外的数据来确保它呈现为数组array()

'attendees'=>array(array(
    'emailAddress'=>array('address'=>'email', 'name'=>'name'),
    'type'=>'required'
)),
相关问题