我在共享驱动器的两个文件夹中创建了两个手表。如果有人添加或更新文件夹中的任何文件,我希望收到通知。
它工作了大约1个月。现在我注意到,如果文件夹中的某些内容发生了变化,Google 不会点击我的 URL。我尝试添加文件、删除文件、更改文件名,但没有任何内容触发更改事件。
仅当我在文件夹上更新(创建新)手表时,Google 才会点击我的 URL。然后我不知道API,直到我再次更新。
我使用 PHP 库:
public function createFileWatch(string $fileId, ?string $token = NULL): Google_Service_Drive_Channel
{
$optParams = [
'fields' => '*',
'supportsAllDrives' => TRUE,
];
$channel = new Google_Service_Drive_Channel();
$channel->setId(Random::generate());
$channel->setType('web_hook');
$channel->setAddress(self::WATCH_REQUEST_URL);
$channel->setExpiration((new DateTime('+1 week'))->getTimestamp() * 1000);
if ($token) {
$channel->setToken($token);
}
return $this->drive->files->watch($fileId, $channel, $optParams);
}