简体   繁体   中英

Not receiving webhook notification from drive, why?

Im trying to use push notification from Google Drive SDK for receive notification for all changes into an account, I follow the steps Registering domain , then creating notification channel and it works, I get this object Google_Service_Drive_Channel from google-api-php-client :

$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
        (
        )

)

So, I go to the google drive account for move some file, but I still don't receive anything from the webhook inside the location specified "address" parameter.

I receive X-Goog-Resource-State = sync header just when the channel is created, but others events like (add, remove, trash, untrash, change, update) don't.

Any help, Thank's

I am guessing the Drive account you're editing isn't associated with that service account, as I don't see you using the sub parameter anywhere. Can you try it with web based OAuth 2.0 as a test so you can establish it is getting access to the same Drive account as the one you are modifying. Take a look at the Drive docs on Application accounts for more on this: https://developers.google.com/drive/web/service-accounts

这是我的bug将域范围权限委托给您的服务帐户的解决方案

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM