我是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()
方法
你能为我提供一些关于它的解释/链接吗?
发布于 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上查看这个完整的项目
https://stackoverflow.com/questions/52762861
复制相似问题