0

I want to fetch Google photos and show into app. I used below code but it is not working.

try {
        val credentialsStream : InputStream = resources.openRawResource(R.raw.credential)

        val credentials: GoogleCredentials =
            GoogleCredentials.fromStream(credentialsStream)
                .createScoped(Collections.singletonList("https://www.googleapis.com/auth/photoslibrary.readonly"))


        val settings = PhotosLibrarySettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
            .build()

        val photosLibraryClient: PhotosLibraryClient = PhotosLibraryClient.initialize(settings)

        val albums: MutableIterable<Album>? = photosLibraryClient.listAlbums().iterateAll()
        if (albums != null) {
            for (album in albums) {
                println("Album title: " + album.title)
                println("Album product URL: " + album.productUrl)
           
            }
        }

    } catch (e: ApiException) {
        JLog.w("Error", "handleSignInResult:error: ${e.message}")
        e.printStackTrace()
    }

I used below libs

implementation ('io.grpc:grpc-okhttp:1.31.1') {
    exclude group: "com.squareup.okhttp"
}
implementation 'com.google.api-client:google-api-client-android:1.31.1'
implementation 'com.google.photos.library:google-photos-library-client:1.7.2'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.7.0'

But when i try to this i got java.lang.NoSuchMethodError: No direct method (Ljava/lang/String;)V in class Lio/grpc/internal/AbstractManagedChannelImplBuilder; or its super classes (declaration of 'io.grpc.internal.AbstractManagedChannelImplBuilder' appears in /data/app/~~MOmfPzH0_A99g7RxMbRc7Q==/com.clicandprint-OwkMyEC4oLeBuyKNeMogtw==/base.apk!classes33.dex) error on this line

 val photosLibraryClient: PhotosLibraryClient = PhotosLibraryClient.initialize(settings)
Pravin Suthar
  • 1,403
  • 1
  • 14
  • 25

1 Answers1

0

I suspect a version mismatch between the gRPC and the photos library client you are using. A couple of observations:

  • The getting started guide for the photos library only lists com.google.photos.library:google-photos-library-client:1.7.2 as a dependency. But I suppose you had to add the others for Android?
  • You are using version 1.31.1 for both grpc-okhttp as well as google-api-client-android. These libraries are not released in tandem and it is just a coincidence they even have a release with the same version number. Picking the same version does not guarantee they work together. 1.31.1 is also quite an old version for both libraries.

I would try using latest versions of both grpc-okhttp as well as google-api-client-android (or try leaving that out).

Terry
  • 91
  • 4