Reputation: 85
Since Yesterday morning I'm stuck with a google drive API request.
As explained here : https://developers.google.com/drive/api/v3/push
I'm trying to subscribe to notifications sending this request :
Url : https://www.googleapis.com/drive/v3/changes/watch
Header :
Content-type: application/json
Authorization: Bearer my_auth_token
{
"id":"An ID generated",
"type":"web_hook",
"address":"my callback address",
}
The response is a code 400 with this body :
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter: pageToken",
"locationType": "parameter",
"location": "pageToken"
}
],
"code": 400,
"message": "Required parameter: pageToken"
}
}
This parameter isn't required according for this subscription request but for this one (same url..) : https://developers.google.com/drive/api/v3/reference/changes/watch
Am I missing / misunderstanding something or is there a problem with the documentation ?
Thank you
Upvotes: 3
Views: 3576
Reputation: 103
The pageToken
parameter is the token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response or to the response from the getStartPageToken method, as we see here.
Therefore, you should pass the pageToken
as a parameter to your URL:
Url: https://www.googleapis.com/drive/v3/changes/watch?pageToken=[YOUR_PAGE_TOKEN_NUMBER_HERE]
for example: https://www.googleapis.com/drive/v3/changes/watch?pageToken=101
It might be interesting to use GET https://www.googleapis.com/drive/v3/changes/startPageToken
to gets the starting pageToken for listing and watch future changes. See here
Upvotes: 2
Reputation: 6791
You might be confused, checking the documentation, if you are making watch requests it should be under this post URL https://www.googleapis.com/apiName/apiVersion/resourcePath/watch
and not https://www.googleapis.com/drive/v3/changes/watch
which is why you are receiving an error "Required parameter: pageToken".
Here is the full watch request code:
POST https://www.googleapis.com/drive/v3/files/fileId/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://yourdom.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myFilesChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
Don't forget register your domain first. Hope this helps.
Upvotes: 0