繁体   English   中英

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

[英]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云端硬盘的通知响应中获取事件名称?

例如:如果我关闭文件,则事件名称作为响应,例如关闭等。

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

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

欢迎访问有关提出手表要求的文章, 获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM