【发布时间】:2019-09-17 10:45:22
【问题描述】:
我一直在使用以下 Java 方法在 GCS 中设置存储桶通知。
private void setBucketNotification(String bucketName, String topicId) {
List<String> eventType = new ArrayList<>();
eventType.add("OBJECT_FINALIZE");
try {
Notification notification = new Notification();
notification.setTopic(topicId);
notification.setEventTypes(eventType);
notification.setPayloadFormat("JSON_API_V1");
final GoogleCredential googleCredential = GoogleCredential
.fromStream(Objects.requireNonNull(classloader.getResourceAsStream("Key.json")))
.createScoped(Collections.singletonList(StorageScopes.DEVSTORAGE_FULL_CONTROL));
final com.google.api.services.storage.Storage myStorage = new com.google.api.services.storage.Storage.Builder(
new NetHttpTransport(), new JacksonFactory(), googleCredential).build();
Notification v = myStorage.notifications().insert(bucketName, notification).execute();
} catch (IOException e) {
log.error("Caught an IOException {}",e);
}
}
到目前为止它运行良好,但最近,我收到了关于 GoogleCredential 类的弃用的投诉,并尝试进行一些研究以希望找到可能的替代品,但找不到任何东西。谁能帮我指出正确的方向?
【问题讨论】:
-
您在哪里看到
GoogleCredential已被弃用? -
也许您需要更改您正在使用的库? google-auth-library-java 或 com.google.apis:google-api-services-oauth2:v1-rev155-1.25.0
-
@JohnHanley 初始化的地方。
-
请在您的问题中包含确切的信息。我的构建没有显示已弃用的消息。您使用的是哪个 Java 版本和 JDK?
-
@JohnHanley 它只是说'com.google.api.client.googleapis.auth.oauth2.GoogleCredential 已弃用'。我不知道除此之外我能有多准确和清晰。我正在使用 java 版本“1.8.0_212”。
标签: java google-cloud-platform google-cloud-storage