我已经用Java实现了Google驱动器推送通知,要接收我创建的频道的通知,请参见以下代码:
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();
}
通道创建成功,当我更改或删除或上传驱动器文件时,我从Google驱动器收到所有事件的相同通知。 下面是我的通知侦听器代码:
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);
}
如何从Google云端硬盘的通知响应中获取事件名称?
示例:如果我关闭文件,则事件名称作为响应,例如关闭等。
答案 0 :(得分:0)