我尝试使用Google云端硬盘SDK中的push notification来接收帐户所有更改的通知,我按照Registering domain的步骤操作,然后创建notification channel并且它有效,我得到了这个来自google-api-php-client的对象Google_Service_Drive_Channel
:
$client = new Google_Client();
$client->setApplicationName("APP_NAME");
$service = new Google_Service_Drive($client);
$key = file_get_contents('my_private_key_location.p12');
$cred = new Google_Auth_AssertionCredentials(
'email_address_from_the_client@developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/drive'),
$key
);
$client->setAssertionCredentials($cred);
// Channel
$channel = new Google_Service_Drive_Channel();
$channel->setId(uniqid());
$channel->setAddress('https://my.custom.url');
$channel->setKind('api#channel');
$channel->setType('web_hook');
$test = $service->changes->watch($channel);
print_r($test);
// Response printing the result
Google_Service_Drive_Channel Object
(
[address] =>
[expiration] => 1407171497000
[id] => xxxxxxxxxxxxxxxxxx
[kind] => api#channel
[params] =>
[payload] =>
[resourceId] => xxxxxxxxxxxxxxxxxxxx
[resourceUri] => https://www.googleapis.com/drive/v2/changes?includeDeleted=true&includeSubscribed=true&maxResults=100&alt=json
[token] =>
[type] =>
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
所以,我去谷歌驱动器帐户移动一些文件,但我仍然没有从指定“地址”参数的位置内的webhook收到任何内容。
我在创建频道时收到X-Goog-Resource-State = sync
标题,但其他事件(如添加,删除,删除,删除,更改,更新)则不会。
任何帮助,谢谢
答案 0 :(得分:1)
我猜您正在编辑的云端硬盘帐户与该服务帐户无关,因为我没有看到您在任何地方使用子参数。您可以尝试使用基于Web的OAuth 2.0作为测试,这样您就可以确定它可以访问与您正在修改的帐户相同的云端硬盘帐户。有关详细信息,请参阅应用帐户的云端硬盘文档:https://developers.google.com/drive/web/service-accounts
答案 1 :(得分:1)