gpt4 book ai didi

java - 通过 Java 访问 google photos API

转载 作者:行者123 更新时间:2023-11-29 07:25:58 29 4
gpt4 key购买 nike

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

你能给我一些解释/链接吗?

最佳答案

您可以创建一个 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

关于java - 通过 Java 访问 google photos API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52762861/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com