我在使用用于Microsoft Graph的php库同步outlook.live.com日历中的事件时遇到问题。
当我执行delta查询以将新事件添加到Outlook日历时,我收到已删除的事件,而不是返回新事件。
我的查询:
/beta/users/{userId}/calendars/{CalendarId}=/calendarView/delta?$deltatoken={deltatoken}
我得到了回应:
array(3) { ["@odata.context"]=> string(60) "https://graph.microsoft.com/beta/$metadata#Collection(event)" ["@odata.deltaLink"]=> string(523) "https://graph.microsoft.com/beta/users/{userid}/calendars/{Calendarid}/calendarView/delta?$deltatoken=VLoBDbMAW0qt42orhN1P_K-qpJgWEpyLQD3OQNZD4Oq1X-2qdILwT6qcenOJ4pg1SIrCY2XWWOEWX909SipAXkdT1f5_HvmIeOV401E2_SRuq37btKNElPw5OcmQh0yE1XvjPNL78Lpmnlg17dJAxyYY-sHWwF9-E0R1DkDtQM27Oc3cpEf7wrstQciCfYJRzRmVgaefdO4fNrsIXEQYIJ5Ui88_-IZA5WtiNffpWME.s-FenjlawGT-DdS6Bzo3MAhc9v1Na9bN8l3Y7YSC9xk" ["value"]=> array(1) { [0]=> array(3) { ["@odata.type"]=> string(22) "#microsoft.graph.event" ["id"]=> string(140) "AQMkADAwATNiZmYAZC1jNGI4LTlkNjctMDACLTAwCgBGAAADufkn5zrCbEu9_NPar0cGNQcAHVeViMrRMU6xEww1vqDblAAAANeIC7oAAAAdV5WIytExTrETDDW_oNuUAAECoeU1AAAA" ["@removed"]=> array(1) { ["reason"]=> string(7) "deleted" } } } }
我的代码如下所示:
$pdo=new PDO("mysql:host=10.0.2.200;port=3306;dbname=$db", {your username},{your password},array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
$query="SELECT * FROM sync_data WHERE id=$id";
$stmt=$pdo->prepare($query);
$stmt->execute();
while($val= $stmt->fetch(PDO::FETCH_ASSOC)){
if ($val["syncTo"]=='Outlook'){
$accessToken=new Token\AccessToken(json_decode($val["accessToken"],true));
$deltaLink=$val["syncToken"];
$calendarId=$val["calendarId"];
}
}
$graph=new Microsoft\Graph\Graph();
$graph->setAccessToken($accessToken);
$response = $graph->createRequest("GET", $deltaLink)
->addHeaders(array ("Prefer"=>"outlook.body-content-type='text'"))
->execute();
$response=$response->getBody();
var_dump($response);
我发现在关于删除事件的响应中提供的id实际上是已创建事件的id,而O'm能够通过这样的get请求来提取事件详细信息:
$url = "/me/calendars/$calendarid/events/AQMkADAwATNiZmYAZC1jNGI4LTlkNjctMDACLTAwCgBGAAADufkn5zrCbEu9_NPar0cGNQcAHVeViMrRMU6xEww1vqDblAAAANeIC7oAAAAdV5WIytExTrETDDW_oNuUAAECoeU1AAAA";
$response = $graph->createRequest("GET", $url)
->addHeaders(array ("Prefer"=>"outlook.body-content-type='text'"))
->execute();
$response=$response->getBody();
答案 0 :(得分:0)
这是设计使然,增量查询响应包含所有更改。删除的事件应包含@removed批注,以便您可以知道删除了哪些事件以及哪些是新的/更新的。