【问题标题】:Webhook notifications for Google drive changes not received未收到有关 Google 云端硬盘更改的 Webhook 通知
【发布时间】:2017-06-14 18:26:53
【问题描述】:

我按照以下步骤为我的服务帐户设置了 webhook 通知

  1. 在开发者控制台中的 IAM 下为我的服务帐户生成私钥
  2. 在开发者控制台中我的应用程序的域验证下添加了我的回调域

  3. 使用以下代码为我的应用程序注册网络挂钩

    java.io.File file = new java.io.File("/xyz.p12");
    FileInputStream fis = new FileInputStream(file);
    PrivateKey serviceAccountPrivateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), fis, "notasecret", "privatekey", "notasecret");
    
        JsonFactory jsonFactory = new JacksonFactory();
                            HttpTransport t = GoogleNetHttpTransport.newTrustedTransport();
        GoogleCredential gc = new GoogleCredential.Builder().setTransport(t)
         .setJsonFactory(jsonFactory)
         .setServiceAccountScopes(Collections.singleton(DriveScopes.DRIVE))
         .setServiceAccountPrivateKey(serviceAccountPrivateKey)
         .setServiceAccountId("xyz")
         .setServiceAccountUser("abc")
         .build();
        Drive drive = new Drive.Builder(t, jsonFactory,null).setHttpRequestInitializer(gc)
         .setApplicationName("xyz").build();
        Channel channel = new Channel(); 
    String uid = UUID.randomUUID().toString(); 
    System.out.println(" UID :: " + uid);
    channel.setId(uid);
    channel.setType("web_hook");
    channel.setAddress("--- Callback URL");
    StartPageToken pageToken = drive.changes().getStartPageToken().execute();
    Channel c = drive.changes().watch(pageToken.getStartPageToken(), channel).execute();
    

代码运行成功,并且我在注册过程中接到了对 webhook 的调用(可能是)。

但是,当我对集成到我的应用程序的驱动器帐户中的驱动器文件进行更改时,我没有收到 webhook 通知。有人可以告诉我我在这个过程中是否遗漏了什么?

顺便说一句,我参考了这个问题的代码

Google push notifications - Unauthorized WebHook callback channel

【问题讨论】:

    标签: java notifications google-drive-api webhooks


    【解决方案1】:

    请注意,除非当前用户或服务帐户拥有或有权访问此资源,如 documentation 中所述,否则监视请求将不会成功。

    每个可监视的 Drive API 资源在以下形式的 URI 处都有一个关联的监视方法:

    https://www.googleapis.com/apiName/apiVersion/resourcePath/watch

    要为有关特定资源更改的消息设置通知通道,请向资源的watch 方法发送POST 请求。

    您也可以查看此related SO post,它也未收到来自 Google Drive 的 webhook 通知。建议的操作是delegate domain-wide authority to your service account

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多