Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

php - 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 protected]',
  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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...