Google Photos Java API 接入 问题

2018-10-01 13:00:10 +08:00
 xarrow

按照官方的栗子, 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 的经验么? 请教~

2048 次点击
所在节点    Java
1 条回复
wpl980
2018-10-02 11:33:18 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/494386

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX