1

我想使用 google-api-client 将照片上传到 Google-Photo。这是我的代码:

毕业文件:

    api 'com.google.api-client:google-api-client:1.26.0'
    api 'com.google.api-client:google-api-client-android:1.26.0'
    api 'io.grpc:grpc-okhttp:1.16.1'
    api 'com.google.photos.library:google-photos-library-client:1.0.1'
    api 'com.google.android.gms:play-services-auth:16.0.1'
    api 'com.google.android.gms:play-services-drive:16.0.0'

初始化照片客户端:

private fun initializePhotoClient(): PhotosLibraryClient? {
    val token = authRepository.getAccessToken()
    val credentials = googleAuth.getUserCredentials(token) ?: return null
    val settings = PhotosLibrarySettings.newBuilder()
            .setCredentialsProvider { credentials }.build()
    return PhotosLibraryClient.initialize(settings)
}

上传文件:

val fileName = localFileProvider.getFileName(uri)
            val uploadRequest = UploadMediaItemRequest.newBuilder()
                    .setFileName(fileName)
                    .setDataFile(RandomAccessFile(uri, "r"))
                    .build()
            val uploadResponse = photosLibraryClient.uploadMediaItem(uploadRequest)

uploadMediaItem方法总是返回如下错误。有谁知道如何解决这一问题?请给我一个提示。

10-27 22:05:47.881 22671-22767/com.smilebooth.easyshare E/AndroidRuntime: FATAL EXCEPTION: android_2
    Process: com.smilebooth.easyshare, PID: 22671
    java.lang.NoSuchMethodError: No static method catching(Lcom/google/common/util/concurrent/ListenableFuture;Ljava/lang/Class;Lcom/google/common/base/Function;)Lcom/google/common/util/concurrent/ListenableFuture; in class Lcom/google/common/util/concurrent/Futures; or its super classes (declaration of 'com.google.common.util.concurrent.Futures' appears in /data/app/com.smilebooth.easyshare-_OaEo0xawrKXOX90QnGu-Q==/split_lib_dependencies_apk.apk!classes2.dex)
        at com.google.api.core.ApiFutures.catching(ApiFutures.java:77)
        at com.google.photos.library.v1.upload.PhotosLibraryUploadUnaryCallable.futureCall(PhotosLibraryUploadUnaryCallable.java:50)
        at com.google.photos.library.v1.upload.PhotosLibraryUploadUnaryCallable.futureCall(PhotosLibraryUploadUnaryCallable.java:31)
        at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
        at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
        at com.google.photos.library.v1.PhotosLibraryClient.uploadMediaItem(PhotosLibraryClient.java:125)
        at com.smilebooth.data.repository.ShareDataRepository.uploadPhotoContent(ShareDataRepository.kt:201)
        at com.smilebooth.data.repository.ShareDataRepository.share(ShareDataRepository.kt:104)
        at com.smilebooth.domain.usecase.ShareUseCase$buildUseCaseObservable$1.subscribe(ShareUseCase.kt:21)
        at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
        at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:260)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)

更新:添加将 photosLibraryClient 初始化为 @Ricardo 所需的函数。照片客户端可以正常工作,因为我可以毫无问题地创建相册

4

1 回答 1

0

降级 grpc-okhttp 库使它对我有用。我使用这个版本:

implementation 'io.grpc:grpc-okhttp:1.15.1'

从那时起,Future 类中肯定发生了一些变化,而且 Google 照片库还没有更新以适应这些变化。

于 2018-11-14T15:42:30.953 回答