[英]Create Google Drive channel for PUSH notification using Service Account
[英]How to get event name of notification from DRIVE API using drive push notification?
我已經在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雲端硬盤的通知響應中獲取事件名稱?
例如:如果我關閉文件,則事件名稱作為響應,例如關閉等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.