通过Java访问Google Photos API [英] Access google photos API via Java

查看:108
本文介绍了通过Java访问Google Photos API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是google API的新手,遇到了麻烦.我用红色文档适用于Java的Google photos API ,然后创建了并在Google API控制台中下载OAuth凭据(credentials.json文件). 之后,我尝试访问google照片.这是文档中的代码:

I am very new to google API and I am having troubles with it. I red documentation Google photos API for Java, then I created OAuth credentials in google API console and downloaded it (credentials.json file). After that I tried to access google photos. Here is code from documentation:

// 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()方法

But I don't understand how to create Credentials object to pass it to the FixedCredentialsProvider.create() method

能否请您提供一些解释/链接?

Could you please provide me with some explanation/links about it?

推荐答案

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

You can create a UserCredentials Object and pass it

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

Or check out this complete project on github https://github.com/erickogi/AndroidGooglePhotosApi

这篇关于通过Java访问Google Photos API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆