Google Drive API-检测文件是否被替换

时间:2018-10-26 10:03:56

标签: google-drive-api

我正在尝试使用Google Grive API通过Retrieving changes method检测文件更改。这是我的代码:

public function detectChangedFiles($service)
{
    $string = file_get_contents(__DIR__ . 'startPageToken.json');
    $json_a = json_decode($string, true);

    $pageToken = $json_a['savedStartPageToken'];

    while ($pageToken != null) {
        $response = $service->changes->listChanges($pageToken, array(
            'spaces' => 'drive',
            'includeCorpusRemovals' => true,
            'includeRemoved' => true,
            'supportsTeamDrives' => true,
            'includeTeamDriveItems' => true
        ));

        foreach ($response->changes as $change) {
            // Process change
            $changedFileId = $change->fileId;
            printf("\nChange found for file: %s", $changedFileId);
        }

        if ($response->newStartPageToken != null) {
            // Last page, save this token for the next polling interval
            $newStartPageToken = $response->newStartPageToken;

            //here I'm saving new start page token to json file
            $this->saveJsonStartPageToken($newStartPageToken);
        }

        $pageToken = $response->nextPageToken;
    }
}

问题是,当我使用相同的名称将文件上传到Google云端硬盘并创建新版本时,我的代码未将此操作检测为更改。有什么方法可以检测到这种文件更新吗?

0 个答案:

没有答案