0

I want to create an application that will download all my photos in Google Photos. I thought it should be easy with the API available.

This should be an CLI application that will run periodically from cron. But when I looked at the Google Photos API, they use OAuth2. The sample shows the usage of FixedCredentials:

PhotosLibrarySettings settings =
     PhotosLibrarySettings.newBuilder()
    .setCredentialsProvider(
        FixedCredentialsProvider.create(/* Add credentials here. */)) 
    .build();

The problem is the part where the /* Add credentials here. */ is. How can I provide my user credentials there? There are numerous classes that implement Credentials but none of them look like ones that would allow me to automate retrieval in a CLI application.

The only thing I get from Google is the client_id and client_token for my app, but how to turn that into an access/refresh token so I can use it without my interaction?

I really hope I don't need to launch a web browser to download my photos.

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115

1 Answers1

1

The Google Photos Library API only accepts OAuth User Credentials. This means that users are required to complete the Google OAuth Flow, which means browser based Authorization.

Note: The Library API does not support service accounts. Your application must use the other OAuth 2.0 flows available such as OAuth 2.0 for web server applications or OAuth 2.0 for mobile and desktop apps.

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.

This links details these requirements:

Authentication and authorization scopes

John Hanley
  • 74,467
  • 6
  • 95
  • 159