Class PhotosLibraryClient
- java.lang.Object
-
- com.google.photos.library.v1.internal.InternalPhotosLibraryClient
-
- com.google.photos.library.v1.PhotosLibraryClient
-
- All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource
,java.lang.AutoCloseable
public final class PhotosLibraryClient extends InternalPhotosLibraryClient
An wrapper class ofInternalPhotosLibraryClient
.Client to interact with the Google Photos Library API. You can perform the following actions on behalf of the user:
- upload media items directly to their Google Photos library
- create albums
- add media items (including album enrichments) to albums
- list and download content from their Google Photos library
- filter results by media type, date range or content category
- create, join, and access shared albums
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
PhotosLibrarySettings photosLibrarySettings = PhotosLibrarySettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) .build(); try (PhotosLibraryClient photosLibraryClient = PhotosLibraryClient.initialize(photosLibrarySettings)) { Album createdAlbum = photosLibraryClient.createAlbum("My Album"); }
Note: close() needs to be called on the photosLibraryClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- 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.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
Do not use
InternalPhotosLibraryClient.create()
orInternalPhotosLibraryClient.create(InternalPhotosLibrarySettings)
for this wrapper.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.photos.library.v1.internal.InternalPhotosLibraryClient
InternalPhotosLibraryClient.ListAlbumsFixedSizeCollection, InternalPhotosLibraryClient.ListAlbumsPage, InternalPhotosLibraryClient.ListAlbumsPagedResponse, InternalPhotosLibraryClient.ListMediaItemsFixedSizeCollection, InternalPhotosLibraryClient.ListMediaItemsPage, InternalPhotosLibraryClient.ListMediaItemsPagedResponse, InternalPhotosLibraryClient.ListSharedAlbumsFixedSizeCollection, InternalPhotosLibraryClient.ListSharedAlbumsPage, InternalPhotosLibraryClient.ListSharedAlbumsPagedResponse, InternalPhotosLibraryClient.SearchMediaItemsFixedSizeCollection, InternalPhotosLibraryClient.SearchMediaItemsPage, InternalPhotosLibraryClient.SearchMediaItemsPagedResponse
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PhotosLibraryClient(PhotosLibraryStub stub, PhotosLibraryUploadStub uploadStub)
protected
PhotosLibraryClient(PhotosLibrarySettings settings)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BatchCreateMediaItemsResponse
batchCreateMediaItems(java.lang.String albumId, java.util.List<NewMediaItem> newMediaItems)
Creates one or more media items in a user's Google Photos library and adds them to an album.BatchCreateMediaItemsResponse
batchCreateMediaItems(java.util.List<NewMediaItem> newMediaItems)
Creates one or more media items in a user's Google Photos library.Album
createAlbum(java.lang.String albumTitle)
Creates an album in a user's Google Photos library.static PhotosLibraryClient
initialize(PhotosLibrarySettings settings)
Creates anPhotosLibraryClient
instance withPhotosLibrarySettings
.InternalPhotosLibraryClient.ListAlbumsPagedResponse
listAlbums()
Lists all albums shown to a user in the Albums tab of the Google Photos app.InternalPhotosLibraryClient.ListMediaItemsPagedResponse
listMediaItems()
List all media items in a user's Google Photos library.InternalPhotosLibraryClient.ListSharedAlbumsPagedResponse
listSharedAlbums()
Lists all shared albums available in the Sharing tab of the user's Google Photos app.UploadMediaItemResponse
uploadMediaItem(UploadMediaItemRequest request)
Uploads a file to Google Photos.com.google.api.gax.rpc.UnaryCallable<UploadMediaItemRequest,UploadMediaItemResponse>
uploadMediaItemCallable()
Returns a callable to upload a file to Google Photos.-
Methods inherited from class com.google.photos.library.v1.internal.InternalPhotosLibraryClient
addEnrichmentToAlbum, addEnrichmentToAlbum, addEnrichmentToAlbumCallable, awaitTermination, batchAddMediaItemsToAlbum, batchAddMediaItemsToAlbum, batchAddMediaItemsToAlbumCallable, batchCreateMediaItems, batchCreateMediaItems, batchCreateMediaItemsCallable, batchGetMediaItems, batchGetMediaItems, batchGetMediaItemsCallable, batchRemoveMediaItemsFromAlbum, batchRemoveMediaItemsFromAlbum, batchRemoveMediaItemsFromAlbumCallable, close, create, create, create, createAlbum, createAlbum, createAlbumCallable, getAlbum, getAlbum, getAlbumCallable, getMediaItem, getMediaItem, getMediaItemCallable, getSettings, getSharedAlbum, getSharedAlbum, getSharedAlbumCallable, getStub, isShutdown, isTerminated, joinSharedAlbum, joinSharedAlbum, joinSharedAlbumCallable, leaveSharedAlbum, leaveSharedAlbum, leaveSharedAlbumCallable, listAlbums, listAlbums, listAlbumsCallable, listAlbumsPagedCallable, listMediaItems, listMediaItemsCallable, listMediaItemsPagedCallable, listSharedAlbums, listSharedAlbums, listSharedAlbumsCallable, listSharedAlbumsPagedCallable, searchMediaItems, searchMediaItems, searchMediaItems, searchMediaItemsCallable, searchMediaItemsPagedCallable, shareAlbum, shareAlbum, shareAlbumCallable, shutdown, shutdownNow, unshareAlbum, unshareAlbum, unshareAlbumCallable
-
-
-
-
Constructor Detail
-
PhotosLibraryClient
protected PhotosLibraryClient(PhotosLibrarySettings settings) throws java.io.IOException
- Throws:
java.io.IOException
-
PhotosLibraryClient
protected PhotosLibraryClient(PhotosLibraryStub stub, PhotosLibraryUploadStub uploadStub)
-
-
Method Detail
-
initialize
public static PhotosLibraryClient initialize(PhotosLibrarySettings settings) throws java.io.IOException
Creates anPhotosLibraryClient
instance withPhotosLibrarySettings
.- Throws:
java.io.IOException
-
uploadMediaItemCallable
public final com.google.api.gax.rpc.UnaryCallable<UploadMediaItemRequest,UploadMediaItemResponse> uploadMediaItemCallable()
Returns a callable to upload a file to Google Photos.
-
uploadMediaItem
public final UploadMediaItemResponse uploadMediaItem(UploadMediaItemRequest request)
Uploads a file to Google Photos.
-
batchCreateMediaItems
public final BatchCreateMediaItemsResponse batchCreateMediaItems(java.util.List<NewMediaItem> newMediaItems)
Creates one or more media items in a user's Google Photos library.The items are only added to the library and not to an album.
- Parameters:
newMediaItems
- List of media items to be created.- See Also:
InternalPhotosLibraryClient.batchCreateMediaItems(String, List, AlbumPosition)
-
batchCreateMediaItems
public final BatchCreateMediaItemsResponse batchCreateMediaItems(java.lang.String albumId, java.util.List<NewMediaItem> newMediaItems)
Creates one or more media items in a user's Google Photos library and adds them to an album.- Parameters:
albumId
- Identifier of the album where the media items are added. The media items are also added to the user's library.newMediaItems
- List of media items to be created.- See Also:
InternalPhotosLibraryClient.batchCreateMediaItems(String, List, AlbumPosition)
-
createAlbum
public final Album createAlbum(java.lang.String albumTitle)
Creates an album in a user's Google Photos library.- Parameters:
albumTitle
- Name of the album displayed to the user in their Google Photos account. This string shouldn't be more than 500 characters.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call failsjava.lang.IllegalArgumentException
- if albumTitle is null or empty.
-
listAlbums
public final InternalPhotosLibraryClient.ListAlbumsPagedResponse listAlbums()
Lists all albums shown to a user in the Albums tab of the Google Photos app.Calls
InternalPhotosLibraryClient.listAlbums(boolean)
with excludeNonAppCreateData set to false.
-
listMediaItems
public final InternalPhotosLibraryClient.ListMediaItemsPagedResponse listMediaItems()
List all media items in a user's Google Photos library.Calls
InternalPhotosLibraryClient.listMediaItems(ListMediaItemsRequest)
with an emptyListMediaItemsRequest
.
-
listSharedAlbums
public final InternalPhotosLibraryClient.ListSharedAlbumsPagedResponse listSharedAlbums()
Lists all shared albums available in the Sharing tab of the user's Google Photos app.Calls
InternalPhotosLibraryClient.listSharedAlbums(boolean)
with excludeNonAppCreateData set to false.
-
-