【问题标题】:nextSyncToken is always empty in the list responce列表响应中的下一个同步令牌始终为空
【发布时间】:2017-03-07 15:13:31
【问题描述】:

我正在尝试从 PHP 制作一个 google 同步方法,我需要接收 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;

第一次调用的同步令牌为空,然后应该添加,但响应中也是空的:https://www.screencast.com/t/AZdXQcUNE

另一个问题是事件实例

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

所有事件的项目始终为空:https://www.screencast.com/t/hzHck7a8d。我需要获取所有事件的发生情况。

如果有人知道什么是解决方案,我将不胜感激!

谢谢!

【问题讨论】:

  • 同步令牌没有问题,只有最后一页你得到同步令牌,所有其他调用你得到 nextPageToken
  • 似乎这只是一些非常古老的事件的问题,初始同步正在返回,现在一切正常

标签: api calendar synchronization token instances


【解决方案1】:

移除 $optParams 中的“orderBy”选项

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 2014-04-24
    相关资源
    最近更新 更多