All Projects → google → java-photoslibrary

google / java-photoslibrary

Licence: Apache-2.0 license
Java client library for the Google Photos Library API

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to java-photoslibrary

Photoprism
Photos App powered by Go and Google TensorFlow 🌈
Stars: ✭ 17,946 (+20527.59%)
Mutual labels:  google-photos
timeline
Timeline - A photo organizer
Stars: ✭ 39 (-55.17%)
Mutual labels:  google-photos
google-photos-api-client-go
Google photos api client in go
Stars: ✭ 35 (-59.77%)
Mutual labels:  google-photos
photos
"Fx Fotos" is an opensource gallery app in react native with the same smoothness and features of Google Photos and Apple Photos. It is backend gnostic and connects to decentralized backends like "box", "Dfinity", "Filecoin" and "Crust".
Stars: ✭ 620 (+612.64%)
Mutual labels:  google-photos
react-pig
Arrange images in a responsive, progressive-loading grid managed in JavaScript using CSS transforms.
Stars: ✭ 47 (-45.98%)
Mutual labels:  google-photos
google-photos-vue
Google Photos album viewer built with Vue.js
Stars: ✭ 17 (-80.46%)
Mutual labels:  google-photos
Timeliner
In general, Timeliner obtains items from data sources and stores them in a timeline.
Stars: ✭ 2,911 (+3245.98%)
Mutual labels:  google-photos
google-photos-exif
A tool to populate missing `DateTimeOriginal` EXIF metadata in Google Photos takeout, using Google's JSON metadata.
Stars: ✭ 288 (+231.03%)
Mutual labels:  google-photos
ArchiverForGooglePhotos
A tool to maintain an archive/mirror of your Google Photos library for backup purposes.
Stars: ✭ 104 (+19.54%)
Mutual labels:  google-photos
flickr to google photos migration
A tool for migrating your photo library from Flickr to Google Photos
Stars: ✭ 39 (-55.17%)
Mutual labels:  google-photos
PixelCrop
A Crop library like Google Photos
Stars: ✭ 52 (-40.23%)
Mutual labels:  google-photos
GPhotoApp
This is a GAS library for retrieving and creating the albums and media items using Google Photo API using Google Apps Script (GAS).
Stars: ✭ 25 (-71.26%)
Mutual labels:  google-photos
php-photoslibrary
PHP client library for the Google Photos Library API
Stars: ✭ 75 (-13.79%)
Mutual labels:  google-photos
Ownphotos
Self hosted alternative to Google Photos
Stars: ✭ 2,587 (+2873.56%)
Mutual labels:  google-photos
color-pop
🌈 Automatic Color Pop effect on any image inspired by Google Photos
Stars: ✭ 21 (-75.86%)
Mutual labels:  google-photos
Drag Select Recyclerview
👇 Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.
Stars: ✭ 1,818 (+1989.66%)
Mutual labels:  google-photos
jiotty-photos-uploader
Uploads your media files to Google Photos creating albums based on the directory structure
Stars: ✭ 54 (-37.93%)
Mutual labels:  google-photos
google-photos-upload
Upload a local image directory into an Album in Google Photos (works on mac/pc/linux). Coded in C# .NET Core 3.0
Stars: ✭ 26 (-70.11%)
Mutual labels:  google-photos
google-photos-timezone-fix
Iterates over photos in given Google Photos album and edits date/time/timezone of each photo in order to fix their order
Stars: ✭ 22 (-74.71%)
Mutual labels:  google-photos
gphotos sort
Sort Google Photos album images by filename.
Stars: ✭ 40 (-54.02%)
Mutual labels:  google-photos

Google Photos Library API Java Client Library

This repository contains the Java client library for the Google Photos Library API.

Build Status

Requirements and preparation

  • Java 1.8+
  • Gradle build system >= 6.5.1 or Maven recommended.
  • OAuth 2.0 credentials configured for your project as described below. (Note that to run the samples, use the "other" client type.)

Download the client library

Firstly, download the library or include it in your build configuration. Then, set up OAuth 2.0 credentials to access the API.

Next, you can follow the samples to see the client library in action.

Option 1: Gradle dependency

To use this library with Gradle, add the following dependency to your build.gradle file and replace VERSION_NUMBER with the latest available release):

repositories {
    mavenCentral()
}
dependencies {
    implementation 'com.google.photos.library:google-photos-library-client:VERSION_NUMBER'
}

Option 2: Maven dependency

To use this library with Maven, add the following to your Maven pom.xml file and replace VERSION_NUMBER with the latest available release):

<dependency>
  <groupId>com.google.photos.library</groupId>
  <artifactId>google-photos-library-client</artifactId>
  <version>VERSION_NUMBER</version>
</dependency>

Option 3: Download a release

The releases page contains different artifacts for each library release, including jar files.

Option 4: Clone the repository

Use this method if you want to alter or contribute to this library (e.g., submitting pull requests) or wish to try our samples. When you clone the repository, all files in this repository will be downloaded.

  1. Run git clone https://github.com/google/java-photoslibrary.git at the command prompt.
  2. You'll get a java-photoslibrary directory. Navigate to it by running cd java-photoslibrary.
  3. Open the build.gradle file in your IDE or run ./gradlew assemble at the command prompt to build the project. See ./gradlew tasks to see available tasks

Set up your OAuth2 credentials for Java

The Google Photos Library API uses OAuth2 as the authentication mechanism. Note that the Library API does not support service accounts.

To complete the “Enable the API” and “Configure OAuth2.0” steps in the below procedure, refer to the get started guide in the developer documentation

Follow the below steps:

  1. Set up a Google developers project
  2. Enable the Google Photos Library API in your developer project
  3. Configure OAuth 2.0 credentials, including a callback URI
  4. Either download your OAuth credentials as a JSON file or note your client ID and secret.

To try out the samples in this repository, select "other" as the application type.

This client library works with the Google Auth Library for Java. Specify your client OAuth configuration in the CredentialsProvider when creating the PhotoLibrarySettings for a PhotosLibraryClient object. See the file PhotosLibraryClientFactory.java for an example on how to create a new PhotosLibraryClient object with credentials from the Google Auth Library.

Sample usage

API calls

Here's a short example that shows how to create a new album:

// [START sample_usage]
// 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
}
// [END sample_usage]

The Google Photos Library API should be accessed via the PhotosLibraryClient class, which contains some additional abstractions and utility methods. You should not use the underlying InternalPhotosLibraryClient and associated classes directly.

Google API Extensions

This library uses the *Google API Extensions for Java (GAX Java) library for API access.

In particular, there are three ways of making calls to each of the API's methods:

  • A "flattened" method (recommended). With this type of method, the fields of the request type have been converted into function parameters. Use the class PhotosLibraryClient to make these requests.
  • A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  • A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

Paged responses and Callables

Using the Google API Extensions library, pagination as described in the Google Photos Library API developer documentation is supported via PagedListResponse, for example ListAlbumsPagedResponse.

try {
    // Make a request to list all albums in the user's library
    // Iterate over all the albums in this list
    // Pagination is handled automatically
    ListAlbumsPagedResponse response = photosLibraryClient.listAlbums();

    for (Album album : response.iterateAll()) {
        // Get some properties of an album and do something with them.
        String id = album.getId();
    }
} catch (ApiException e) {
    // Handle error
}

Retry configuration

The default retry configuration follows the AIP guidance for retrying API requests, which is configured in com.google.photos.library.v1.internal.stub.PhotosLibraryStubSettings and com.google.photos.library.v1.PhotosLibrarySettings.

Here's an example that shows how to customize the retry configuration for the getAlbum(..) call and for uploading media bytes:

// Create a new retry configuration.
RetrySettings retrySettings=RetrySettings.newBuilder()
        .setInitialRetryDelay(Duration.ofSeconds(4))
        .setRetryDelayMultiplier(1.5)
        .setMaxAttempts(7)
        .setMaxRetryDelay(Duration.ofSeconds(60))
        .setTotalTimeout(Duration.ofMinutes(15))
        .build();

// Set the status codes returned from the API that should be retried.
 Set<StatusCode.Code>retryableCodes=
        Set.of(StatusCode.Code.DEADLINE_EXCEEDED,StatusCode.Code.UNAVAILABLE);

 PhotosLibrarySettings.Builder librarySettingsBuilder=
        PhotosLibrarySettings.newBuilder();

// Configure these retry settings for the "getAlbums" call.
librarySettingsBuilder.getAlbumSettings()
        .setRetrySettings(retrySettings)
        .setRetryableCodes(retryableCodes);

// Configure these retry settings for the upload media call.
librarySettingsBuilder.updateMediaItemSettings()
        .setRetrySettings(retrySettings)
        .setRetryableCodes(retryableCodes);

// Configure other client options, for example authentication credentials.

// Create the client.
PhotosLibraryClient client = PhotosLibraryClient.initialize(librarySettingsBuilder.build());

Samples

A few examples are included in the sample directory. They show how to access media items, filter media, share albums and upload files.

The API developer documentation also includes code snippets for this client library in Java.

Reference documentation

Javadoc for this library can be found in the gh-pages branch of this repository. You can browse it at https://google.github.io/java-photoslibrary/index.html

General Google Photos Library API documentation can be found on our Google Developers site: https://developers.google.com/photos

Getting support

For client library specific bug reports, feature requests, and patches, create an issue on the issue tracker.

See the support page for any other API questions, bug reports, or feature requests.

Announcements and updates

For general Google Photos Library API and client library updates and news, follow:

License

Copyright 2018 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].