nextSyncToken在列表响应中始终为空

时间:2017-03-07 15:13:32

标签: api calendar synchronization token instances

我尝试从PHP制作谷歌同步方法,我需要接收nextSyncToken进行初始同步以使其正常工作。由于某种原因,它是空的。

使用访问令牌进行连接:

public function __construct()
{
    $this->client = new \Google_Client();
    $this->client->setApplicationName("Stb Agenda 2.0");
    $this->client->setScopes(implode(' ', array(\Google_Service_Calendar::CALENDAR)));

    $this->client->setAuthConfig('/var/www/api/WebAgenda-Api/cert/client_secret_dev_api.json');
    $this->client->setAccessType('offline');
    $this->client->setApprovalPrompt('force');

    $this->service = new \Google_Service_Calendar($this->client);

}

public function authenticate($accessToken){

    $this->client->setAccessToken($accessToken);

    // Refresh the token if it's expired.
    if ($this->client->isAccessTokenExpired()) {
        $this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
        return $this->client->getAccessToken();
    }

}

然后我得到了这些事件:

public function getSyncEvents($calendarId, $syncToken = null)
{

    $options = array(
        'singleEvents' => true,
        'showDeleted' => true
    );
    if($syncToken){
        $options['syncToken'] = $syncToken;
    }

    try {
        $eventObj = $this->service->events->listEvents($calendarId, $options);
    } catch (\Google_Service_Exception $e) {

        $errors = $e->getErrors();

        $fp = fopen("google_sync_log.txt", a);
        fwrite($fp, $e->getCode().' - '.serialize($errors)."\n");
        fclose($fp);

        foreach($errors as $error){
            if($error['reason'] == "fullSyncRequired"){
                $eventObj = $this->service->events->listEvents($calendarId);
            }

        }

    }


    if($eventObj) {

        $events = $eventObj->getItems();

        $nextSyncToken = $eventObj->getNextSyncToken();

        $response = array();
        $response['syncToken'] = $nextSyncToken;

同步toke在第一次调用时为空,然后应该添加,但在响应中它也为空:https://www.screencast.com/t/AZdXQcUNE

另一个问题是事件实例

$ev = $this->service->events->instances($calendarId, $event->getId());
$occurrences = $ev->getItems();

所有活动的项目始终为空:https://www.screencast.com/t/hzHck7a8d。我需要了解所有事件的发生。

如果有人知道什么是解决方案我会非常感激!

谢谢!

1 个答案:

答案 0 :(得分:0)

删除$ optParams中的“ orderBy”选项