Activate notifications for the file with ID [file-id] by posting some JSON to this URL:
https://www.googleapis.com/drive/v3/files/[file-id]/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
Minimal JSON you need to POST:
{
"id": "[some unique ID for your push, you can define it yourself but it mus be unique]",
"type": "web_hook",
"address": "https://www.example.com/catch.php"
}
The answer if all goes well:
{
"kind": "api#channel",
"id": "[some unique ID for your push, you can define it yourself but it must be unique]",
"resourceId": "[resourceId]",
"resourceUri": "https://www.googleapis.com/drive/v3/files/[file-id]?acknowledgeAbuse=false&supportsTeamDrives=false&alt=json",
"expiration": "1526248563000"
}
Note:
- The push notifications will only work for one hour and need to be re-activated after that.
- If you enable notifications for a folder, only the changes for its direct children are shown, not the changes inside the child-folders.
If you set the notifications, you might also need a new oAuth token. If you set the access-type of your app to offline, you can get one using your refresh-token.
Post to this URL:
https://accounts.google.com/o/oauth2/token
Post these variables as x-www-urlencoded:
- client_id
- client_secret
- refresh_token
- grant_type = refresh_token
Beginner question I know? Where do I find or generate the auth_token_for_current_user?