简体   繁体   English

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

[英]How to get event name of notification from DRIVE API using drive push notification?

I have implemented the google drive push notifications in Java, for receiving the notification I have created the channel see below code : 我已经在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();
        }

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. 频道已成功创建,当我更改或删除或上传驱动器文件时,我从Google驱动器收到所有事件的相同通知。 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? 如何在Google云端硬盘的通知响应中获取事件名称?

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: 搜索了获取事件名称通知的方式后,我发现:

  1. There is no way to get event name using changes watch request. 无法使用更改监视请求获取事件名称。
  2. We can get event name in notification using file watch request. 我们可以使用文件监视请求在通知中获取事件名称。

Feel free to visit the article on making watch requests for more information. 欢迎访问有关提出手表要求的文章, 获取更多信息。

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

相关问题 使用服务帐户为推送通知创建 Google Drive 频道 - Create Google Drive channel for PUSH notification using Service Account 如何使用vert.x java api向客户端发送服务器通知(推送通知) - How to get server notification(push notification) to client using vert.x java api 如何使用Java Drive Rest V2 API从Google Drive获取文档和文件的绝对路径? - How to get absolute path of a document and file from Google Drive Using Java Drive Rest V2 API? 如何使用drive api java从谷歌驱动器下载文件? - How to download a file from google drive using drive api java? 如何通过推送通知使用Android Parse触发事件? - How to trigger an event using Parse for Android via push notification? 如何使用Java GCM API在Android设备上获取失败推送通知的注册ID - How to get registration id of failure push notification on android device using Java GCM API 推送事件未触发来自服务器的发送通知 - Push event not firing on send notification from server 如果使用API​​的数据库发生更改,如何显示推送通知? - How to display push notification if there are changes in DB using API? 如何在推送通知中添加点击事件? - How to add click event in push notification? 如何获取多个警报通知的事件名称? - How to get event name for more than one alarm notification?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM