首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >通过Java访问google照片API

通过Java访问google照片API
EN

Stack Overflow用户
提问于 2018-10-11 22:41:19
回答 1查看 2.9K关注 0票数 2

我是google API的新手,我对它有一些问题。我编辑了文档Google photos API for Java,然后在google API控制台中创建了OAuth凭据并下载了它(credentials.json文件)。在那之后,我试着访问谷歌照片。以下是文档中的代码:

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

但是我不知道如何创建Credentials对象来将其传递给FixedCredentialsProvider.create()方法

你能为我提供一些关于它的解释/链接吗?

EN

回答 1

Stack Overflow用户

发布于 2019-02-05 20:02:18

您可以创建一个UserCredentials对象并传递它

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

通过此答案https://stackoverflow.com/a/54533855/6153171

或者在github https://github.com/erickogi/AndroidGooglePhotosApi上查看这个完整的项目

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52762861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档