user5693594
user5693594

Reputation:

drive.changes.watch don't sends notifications

I'm using googleapis npm package ("apis/drive/v3.js") for Google Drive service. On backend I'm using NodeJS and ngrok for local testing. My problem is that I can't get notifications. The following code:

    drive.changes.watch({
        pageToken: startPageToken,
        resource: {
            id: uuid.v1(),
            type: 'web_hook',
            address: 'https://7def94f6.ngrok.io/notifications'
        }
    }, function(err, result) {
        console.log(result)
    });

returns some like:

{
    kind: 'api#channel',
    id: '8c9d74f0-fe7b-11e5-a764-fd0d7465593e',
    resourceId: '9amJTbMCYabCkFvn8ssPrtzWvAM',
    resourceUri: 'https://www.googleapis.com/drive/v3/changes?includeRemoved=true&pageSize=100&pageToken=6051&restrictToMyDrive=false&spaces=drive&alt=json',
    expiration: '1460227829000'
}

When I try to change any files in Google Drive, the notifications do not comes. Dear colleges, what is wrong?

Upvotes: 2

Views: 1867

Answers (1)

AIon
AIon

Reputation: 13081

This should be a comment but i do not have enough (50points) experience to post one. Sorry if this is not a real answer but might help.

I learned this today. I'm doing practically the same thing like you - only not with Drive but Gmail api. I see you have this error:

"push.webhookUrlUnauthorized", "message": "Unauthorized WebHook etc..."

I think this is because one of the 2 reasons:

  1. you didn't give the Drive-api publisher permissions to your topic.

  2. Second if you want to receive notifications, the authorized webHooks Url must be set both on the server( your project) and in your pub/sub service(Google Cloud).

See below - for me this setup works:

1. Create a topic

1. Create a topic

 2. Give the Drive publish permissions to your topic. This is done by adding the Drive scope in the box and following steps 2 and 3.

2. Give the Drive publisher permission to your topic

3. Configure authorized WebHooks. Form the Create Topic page - click on add subscriptions. Not rely vizible here but once you are there you can manage.

3. Configure authorized WebHooks

Upvotes: 2

Related Questions