Webhook notifications for Google drive changes not received

十年热恋 提交于 2019-12-25 08:21:47

问题


I set up webhook notification for my service account following the below steps

  1. Generated private key for my service account under IAM in developer console
  2. Added my callback domain under Domain verification in my application in the developers console

  3. Used the below code to register the web hook for my application

    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();
    

The code runs successfully and also I got a call to the webhook as part of the registration (may be).

But when I make changes to the drive files in the drive account which is integrated to my application, I don't get webhook notification. Can someone please tell me whether I am missing something in the process?

Btw I referred the code from this question

Google push notifications - Unauthorized WebHook callback channel


回答1:


Be noted that a watch request will not be successful unless the current user or service account owns or has permission to access this resource as stated in this documentation.

Each watchable Drive API resource has an associated watch method at a URI of the following form:

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

To set up a notification channel for messages about changes to a particular resource, send a POST request to the watch method for the resource.

You may also check on this related SO post which is also Not receiving webhook notification from Google Drive. Suggested action is to delegate domain-wide authority to your service account.



来源:https://stackoverflow.com/questions/41921648/webhook-notifications-for-google-drive-changes-not-received

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!