如何使用驱动器推送通知从DRIVE API获取通知的事件名称



我已经在Java中实现了谷歌驱动器推送通知,为了接收通知,我已经创建了通道,请参阅下面的代码:

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();
}

频道创建成功,当我更改、删除或上传驱动器文件时,我会从谷歌驱动器收到所有事件的相同通知。下面是我的通知侦听器代码:

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);
}

如何从谷歌驱动器获取通知响应中的事件名称?

示例:如果我关闭文件,那么像关闭等响应中的事件名称

在搜索了使用事件名称获取通知的方式后,我发现:

  1. 无法使用更改监视请求获取事件名称
  2. 我们可以使用文件监视请求在通知中获取事件名称

请随时访问关于制作手表请求的文章以获取更多信息。

最新更新