Google图书馆照片Api

时间:2018-11-15 12:31:26

标签: java android google-photos google-photos-api

 // 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
}

所以我的问题是如何在此参数上传递凭据? (我想在本机android而不是Web应用程序或后端服务器上使用它)我确实很挣扎,虽然我可以使用google登录来获取凭据,但可以登录google了,这会很棒:)

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

创建UserCredetials对象

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

并将其传递给FixedCredentialsProvider.create())

看看这个项目以获取完整的代码 https://github.com/erickogi/AndroidGooglePhotosApi/blob/master/app/src/main/java/ke/co/calista/googlephotos/Utils/PhotosLibraryClientFactory.kt