更新时间:2023-02-19 13:54:54
环顾四周后,我设法使用 GoogleCredentials
和 HttpRequestInitializer
修复了它.代码改动如下.
After a while of looking around, I managed to fix it, using GoogleCredentials
and HttpRequestInitializer
. The code changes are as follows.
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();
变成
final GoogleCredentials googleCredentials = serviceAccountCredentials
.createScoped(Collections.singletonList(StorageScopes.DEVSTORAGE_FULL_CONTROL));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(googleCredentials);
final com.google.api.services.storage.Storage myStorage = new com.google.api.services.storage.Storage.Builder(
new NetHttpTransport(), new JacksonFactory(), requestInitializer).build();