2

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

Community
  • 1
  • 1
Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105

1 Answers1

0

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.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59