$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...)
我做错了什么?
示例的 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'
)),
下面是 PHP 示例:
"与会者" => [ 数组 (
"emailAddress" => array(
"address" => "user@domain.com",
"name" => "User's first and last name",
),
"type" => "required",
)],