I have implemented the google drive push notifications in Java, for receiving the notification I have created the channel see below code :
notificationchannel.setAddress("https://www.XXXXXX.in/drive/receive/notifications");
notificationchannel.setType("web_hook");
notificationchannel.setId(UUID.randomUUID().toString());
notificationchannel.setExpiration(new Date().getTime() + 86340000);
userDriveService = (Drive)inUtilityObj.getDriveService(userEmail);
if(userDriveService != null) {
StartPageToken pageToken = userDriveService.changes().getStartPageToken().execute();
Channel changesChannel = userDriveService.changes().watch(pageToken.getStartPageToken(), notificationchannel).execute();
}
The channel is created successfully and when i change or remove or upload file of drive i am getting same notifications for all event from google drive. Below is my notification listener code :
try {
String nextPageToken = savedStartPageToken;
while (nextPageToken != null) {
ChangeList changes = driveService.changes().list(nextPageToken).execute();
log.warning(" *** ChangeList ::" + changes.getChanges());
for (Change changeObj : changes.getChanges()) {
log.warning("File Id::"+changeObj.getFileId() + ",Kind ::"+changeObj.getKind() + ", Team Drive ID::"+changeObj.getTeamDriveId() + ", Type::"+changeObj.getType()+ ",File ::"+changeObj.getFile()+ ", Is Removed::"+changeObj.getRemoved()+ ",Time ::"+changeObj.getTime());
}
if (changes.getNewStartPageToken() != null) {
// Last page, save this token for the next polling interval
savedStartPageToken = changes.getNewStartPageToken(); // store in database
log.warning("savedStartPageToken ::" + savedStartPageToken);
}
nextPageToken = changes.getNextPageToken();
log.warning("nextPageToken ::" + nextPageToken);
}
}catch(Exception ex) {
ErrorHandler.errorHandler(this.getClass().getSimpleName(), ex);
}
How can I get event name in notification response from google drive?
example : if i close the file then event name in response like close etc.
After searching the way of getting notification with event name, I have found that:
Feel free to visit the article on making watch requests for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.