Events 使用Microsoft graph创建事件时出错
此函数“$This->mg_model->idCalendarioUsuario()”返回日历IDEvents 使用Microsoft graph创建事件时出错,events,graph,calendar,composer-php,microsoft-graph-api,Events,Graph,Calendar,Composer Php,Microsoft Graph Api,此函数“$This->mg_model->idCalendarioUsuario()”返回日历ID $p=array( 'subject'=>'Registrado desde iSchool', 'body'=>array( 'contentType'=>'HTML', 'content'=>'Evento de prueba',
$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);
我做错了什么?您示例中的JSON负载应该如下所示:
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...)
但是,您的Attendes集合正在作为对象而不是数组呈现。它将与会者呈现为对象而不是数组。这可能是该有效负载错误的原因
{
"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"
}]
}
请注意,我不是PHP专家,所以这里的代码可能不太雅观。也就是说,我相信您可以通过将它包装在一个附加的数组()中来确保它呈现为一个数组:
在服务器的响应中,错误的消息属性真的被截断了吗?如果没有,那么请包括完整的错误信息。问题正如马克解释的,我已经纠正了。谢谢谢谢,这就是我们缺少的。是否可以从这里添加与会者的手机号码?
"attendees": {
"emailAddress": {
"address": "email",
"name": "name"
},
"type": "required"
}
'attendees'=>array(array(
'emailAddress'=>array('address'=>'email', 'name'=>'name'),
'type'=>'required'
)),