Java 未收到Google驱动器更改的Webhook通知
我按照以下步骤为我的服务帐户设置webhook通知Java 未收到Google驱动器更改的Webhook通知,java,notifications,google-drive-api,webhooks,Java,Notifications,Google Drive Api,Webhooks,我按照以下步骤为我的服务帐户设置webhook通知 在开发者控制台的IAM下为我的服务帐户生成私钥 在开发者控制台的我的应用程序中的域验证下添加了我的回调域 使用以下代码为我的应用程序注册web钩子 java.io.File file = new java.io.File("/xyz.p12"); FileInputStream fis = new FileInputStream(file); PrivateKey serviceAccountPrivateKey = SecurityUtils
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();
请注意,除非当前用户或服务帐户拥有或有权访问此资源,否则监视请求将不会成功 每个可监视驱动器API资源在URI处都有一个关联的监视方法,其形式如下:
https://www.googleapis.com/apiName/apiVersion/resourcePath/watch
要为有关特定资源更改的消息设置通知通道,请向该资源的watch
方法发送POST
请求
您也可以检查一下,这也不会从Google Drive收到webhook通知。建议采取的行动是: