V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xarrow
V2EX  ›  Java

Google Photos Java API 接入 问题

  •  
  •   xarrow · 2018-10-01 13:00:10 +08:00 · 2033 次点击
    这是一个创建于 2006 天前的主题,其中的信息可能已经有所发展或是发生改变。

    按照官方的栗子, 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 条回复    2018-10-02 11:33:18 +08:00
    wpl980
        1
    wpl980  
       2018-10-02 11:33:18 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5652 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 06:31 · PVG 14:31 · LAX 23:31 · JFK 02:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.