gpt4 book ai didi

java - com.google.auth.oauth2.GoogleCredentials.createScoped 处出现 StackOverflowError(GoogleCredentials.java :222)

转载 作者:行者123 更新时间:2023-12-02 08:56:13 25 4
gpt4 key购买 nike

下面的代码在执行时抛出此错误:

Caused by: java.lang.StackOverflowError
at com.google.auth.oauth2.GoogleCredentials.createScoped(GoogleCredentials.java:222)

这段代码可能有什么问题:

public static void uploadToGooglePhotos(File uploadFile) throws Exception {
try {
InputStream stream = new ByteArrayInputStream(GoogleJsonKey.JSON_KEY.getBytes(StandardCharsets.UTF_8));
GoogleCredentials credentials = GoogleCredentials.fromStream(stream)
.createScoped("https://www.googleapis.com/auth/cloud-platform");
credentials.refreshIfExpired();
PhotosLibrarySettings settings =
PhotosLibrarySettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
PhotosLibraryClient photosLibraryClient =
PhotosLibraryClient.initialize(settings);
UploadMediaItemRequest uploadRequest =
UploadMediaItemRequest.newBuilder()
.setFileName(uploadFile.getName())
.setDataFile(new RandomAccessFile(uploadFile.getAbsolutePath(), "r"))
.build();
UploadMediaItemResponse uploadResponse = photosLibraryClient.uploadMediaItem(uploadRequest);
if (uploadResponse.getError().isPresent()) {
UploadMediaItemResponse.Error error = uploadResponse.getError().get();
} else {
String uploadToken = uploadResponse.getUploadToken().get();
}
} catch (ApiException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}

}

最佳答案

您可以尝试以下操作吗:

GoogleCredentials credentials = GoogleCredentials.fromStream(stream).createScoped(Collections.singleton("https://www.googleapis.com/auth/cloud-platform"))

关于java - com.google.auth.oauth2.GoogleCredentials.createScoped 处出现 StackOverflowError(GoogleCredentials.java :222),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60474325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com