Какой правильный способ загрузки фотографий в облако Google Фото с помощью библиотеки фотографий ?
Мой код здесь не работает:
public class App {
public static void main(String[] args) throws Exception {
File videoFile = new File(PATH_TO_VIDEO_FILE);
uploadToGooglePhotos(videoFile);
}
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(Collections.singleton("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();
}
}
}
И он выбрасывает эта ошибка:
Mar 02, 2020 1:59:09 AM io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference cleanQueue
SEVERE: *~*~*~ Channel ManagedChannelImpl{logId=1, target=photoslibrary.googleapis.com:443} was not shutdown properly!!! ~*~*~*
Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:94)
at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:52)
at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:43)
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:514)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:223)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:164)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:156)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:157)
at com.google.photos.library.v1.internal.stub.GrpcPhotosLibraryStub.create(GrpcPhotosLibraryStub.java:286)
at com.google.photos.library.v1.internal.stub.PhotosLibraryStubSettings.createStub(PhotosLibraryStubSettings.java:264)
at com.google.photos.library.v1.internal.InternalPhotosLibraryClient.<init>(InternalPhotosLibraryClient.java:180)
at com.google.photos.library.v1.PhotosLibraryClient.<init>(PhotosLibraryClient.java:101)
at com.google.photos.library.v1.PhotosLibraryClient.initialize(PhotosLibraryClient.java:114)
Использование этих зависимостей:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.30.5</version>
</dependency>
<dependency>
<groupId>com.google.photos.library</groupId>
<artifactId>google-photos-library-client</artifactId>
<version>1.4.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
Что может быть не так в моей настройке? Библиотека current Photos Java не работает?