Google Library Photos Api

656 Views Asked by At
 // Set up the Photos Library Client that interacts with the API
  PhotosLibrarySettings settings =
     PhotosLibrarySettings.newBuilder()
     .setCredentialsProvider(
         FixedCredentialsProvider.create(/* Add credentials here. 
 */)) 
    .build();

 try (PhotosLibraryClient photosLibraryClient =
    PhotosLibraryClient.initialize(settings)) {

    // Create a new Album  with at title
    Album createdAlbum = photosLibraryClient.createAlbum("My 
Album");

// Get some properties from the album, such as its ID and 
product URL
    String id = album.getId();
    String url = album.getProductUrl();

}    catch (ApiException e) {
    // Error during album creation
}

so my question is how to pass credentials on this parameter? (i want to use it on native android not web app or backend server ) im really struggling, got google sign in working though if i can use that to get credentials would be great :)

any help is appreciated!

1

There are 1 best solutions below

1
On

Create a UserCredetials Object

UserCredentials.newBuilder()
    .setClientId("your client id")
    .setClientSecret("your client secret")
    .setAccessToken("Access Token")
    .build()

and pass it to FixedCredentialsProvider.create())

Take a look at this project to get full code https://github.com/erickogi/AndroidGooglePhotosApi/blob/master/app/src/main/java/ke/co/calista/googlephotos/Utils/PhotosLibraryClientFactory.kt