Issue
I have integrated google drive into my application. To achieve sync, I have also configured push notifications for each account by following the steps in the link https://developers.google.com/drive/v3/web/push
Below is the java code to configure watch on all files for the account
String uuid = UUID.randomUUID().toString();
Channel channel = new Channel();
channel.setId(uuid);
channel.setType("web_hook");
channel.setAddress(env.getProperty("webhookUrl"));
StartPageToken pageToken = service.changes().getStartPageToken().execute();
Channel response = service.changes().watch(pageToken.getStartPageToken(), channel).execute();
On making changes in the actual google drive, I get the notification in the webhook url configured above.
But the problem is for every change, I am getting the same values for below headers which are same as the response of the watch call & I am not getting any proper request headers corresponding to the change or request body
//Getting request headers
String resourceId = request.getHeader("X-Goog-Resource-ID");
String resourceState = request.getHeader("X-Goog-Resource-State");
String expiration = request.getHeader("X-Goog-Channel-Expiration");
String resourceChanges = request.getHeader("X-Goog-Changed");
String channelId = request.getHeader("X-Goog-Channel-ID");
Can someone please let me know how do i get notification data correctly ? Is there anything I am doing wrong ?
Here is the same problem stated by another question which does not have proper answer yet Receiving Google Drive Push Notifications
Solution
Actually there is no request body which gets sent in the webhook notification. So as soon as changes arrive in the callback url, changes are to be fetched by making a get request to changes resource uri
Resource URI : https://www.googleapis.com/drive/v3/changes?includeRemoved=true&pageSize=100&pageToken=895&restrictToMyDrive=false&spaces=drive&alt=json
Or programatically changes can be fetched by using the below code
String pageToken = channelInfo.getCurrPageToken();
List<Change> changes = service.changes().list(pageToken)
.execute().getChanges();
Google push notifications doc could have mentioned this clearly rather than mentioning that the changes come along in the request body which is the reason for confusion
Answered By - Aarish Ramesh
Answer Checked By - Robin (JavaFixing Admin)