3
 // 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 应用程序或后端服务器)我真的很挣扎,让谷歌登录工作虽然如果我可以使用它来获取凭据会很棒:)

任何帮助表示赞赏!

4

1 回答 1

0

创建一个 UserCredentials 对象

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

于 2019-02-05T13:01:54.483 回答