按照官方的栗子, https://developers.google.com/photos/library/guides/get-started-java
引入依赖包
<dependency>
<groupId>com.google.photos.library</groupId>
<artifactId>google-photos-library-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>1.32.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.1.0</version>
</dependency>
示例代码:
// 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
}
第一步授权,官网让参考 OAuth2 登录。 通过如下代码得到 Crendentials
private static Credentials getCredentials()throws Exception{
return GoogleCredentials.fromStream(new FileInputStream("b22502c65cac.json"));
}
结果运行提示需要依赖grpc-netty
或者是grpc-http
, 然后问题就来了,这个 grpc 的包真的有毒,各种包冲突,好不容易解决包冲突了,再次运行又是包缺少。
有小伙伴有使用过 Google Photos API 的经验么? 请教~
1
wpl980 2018-10-02 11:33:18 +08:00
|