google-api-nodejs-client: Cannot stop watching a channel

googleapi version: 12.4.0 api version: 3

Steps to reproduce

  1. Start watching a drive file

    drive.files.watch({
      fileId,
      resource: {
        id: 'my-chanel',
        type: 'web_hook',
        address: 'https://example.com/api/gsheets'
      }
    }, (err, result) => {
    ...
    });
    

    It works good, I get info about channel and start receiving notfnications about changes.

  2. Try to stop channel

    drive.channels.stop({
      resource: {
        id: 'my-channel',
        resourceId: 'given resource id goes here'
      }
    }, (err, result) => {
    ...
    });
    

Expected result

Some message about successful operation

Actual result

error:  Error: Channel 'my-channel' not found for project '636397034666'
    at Request._callback (/Users/jifeon/projects/plyo.web/node_modules/google-auth-library/lib/transporters.js:82:15)
    at Request.self.callback (/Users/jifeon/projects/plyo.web/node_modules/google-auth-library/node_modules/request/request.js:198:22)
    at emitTwo (events.js:100:13)
    at Request.emit (events.js:185:7)
    at Request.<anonymous> (/Users/jifeon/projects/plyo.web/node_modules/google-auth-library/node_modules/request/request.js:1057:14)
    at emitOne (events.js:95:20)
    at Request.emit (events.js:182:7)
    at IncomingMessage.<anonymous> (/Users/jifeon/projects/plyo.web/node_modules/google-auth-library/node_modules/request/request.js:1003:12)
    at emitNone (events.js:85:20)
    at IncomingMessage.emit (events.js:179:7)
    at endReadableNT (_stream_readable.js:913:12)
    at _combinedTickCallback (node.js:377:13)
    at process._tickDomainCallback (node.js:425:11)

and if I try to watch again, it says “Channel id is not unique”

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (4 by maintainers)

Most upvoted comments

Also, it’s a little weird to not be able to stop channels with the params you used to create them - if you somehow forget to extract the resourceId from the response are you just stuck getting events until you hit the expiration time?

Was getting the useless “Required” error above too. I had forgotten to put the “id” and “resourceId” inside a “resource” object. This structure is very poorly documented: var params = { "auth": { }, "resource": { "id": "...", "resourceId": "..." } }

The fact that you need the resourceId (which seems to be only returned in the watch request response) to stop events for a particular channel makes channels/events harder to work with.

So to be more precise here, I supplied an ID of a spreadsheet to the watch function, which the service turned into of an ID of the file representing the spreadsheet. So the above documentation is OK as far as you note somewhere that the service will translate the spreadsheet (or any other) id to file id.

ps.: Strange that the drive api accepts spreadsheet ids, but the spreadsheet api does not accept file ids.

I hit the same wall today and what I found is the resourceId returned by the watch method is not the same as I sent.

The documentation says:

Watch response If the watch request successfully creates a notification channel, it returns an HTTP 200 OK status code.

The message body of the watch response provides information about the notification channel you just created, as shown in the example below.

{ “kind”: “api#channel”, “id”: “01234567-89ab-cdef-0123456789ab”", // ID you specified for this channel. “resourceId”: “o3hgv1538sdjfh”, // ID of the watched resource. <- This must be the mistake “resourceUri”: “https://www.googleapis.com/drive/v3/files/o3hgv1538sdjfh”, // Version-specific ID of the watched resource. “token”: “target=myApp-myFilesChannelDest”, // Present only if one was provided. “expiration”: 1426325213000, // Actual expiration time as Unix timestamp (in ms), if applicable. }

In addition to the properties you sent as part of your request, the returned information also includes the resourceId and resourceUri to identify the resource being watched on this notification channel.

Since you are using the same name for those properties and not mentioning anywhere that these are not the same, it is not a miracle that some people gets confused. Please repopen and fix it in the documentation. I assume the returned resourceId is related to the channel itself, and not to the watched resource.

Yep, having the same problem here. Does anybody have a solution on this? How should we get resourceId if not stored?