I set up webhook notification for my service account following the below steps
- Generated private key for my service account under IAM in developer console
Added my callback domain under Domain verification in my application in the developers console
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