Manage albums

In Google Photos, you can organize photos and other media items using albums. A media item can be associated with one or more albums. To start associating media items with an album, you need to create the album first.

Required authentication scope

To create an album, your app must request at least one of the following authorization scopes:

  • .appendonly
  • .sharing
  • .photoslibrary

Creating a new album

To create an album, call albums.create and include the title. Note that title is restricted to 500 characters.

The call returns an album. Your app can store the album ID from this information and use it for uploading media items to the specific album.

REST

Here is a header for a POST request:

POST https://photoslibrary.googleapis.com/v1/albums
Content-type: application/json
Authorization: Bearer OAUTH2_TOKEN

The request body looks like this:

{
  "album": {
    "title": "New Album Title"
  }
}

If successful, the response returns an album:

{
  "productUrl": "ALBUM_PRODUCT_URL",
  "id": "ALBUM_ID",
  "title": "ALBUM_TITLE",
  "isWriteable": "WHETHER_YOU_CAN_WRITE_TO_THIS_ALBUM"
}

Java

try {
  Album createdAlbum = photosLibraryClient.createAlbum("My Album");
  // The createdAlbum object contains properties of an album
  String productUrl = createdAlbum.getProductUrl();
  // coverPhotoBaseUrl shouldn't be used as is. Append parameters to base URLs before use
  String albumCoverImage = createdAlbum.getCoverPhotoBaseUrl() + "=w2048-h1024";
  boolean isWriteable = createdAlbum.getIsWriteable();
} catch (ApiException e) {
  // Handle error
}
    

PHP

try {
    $newAlbum = PhotosLibraryResourceFactory::album("My Album");
    $createdAlbum = $photosLibraryClient->createAlbum($newAlbum);
    // The createdAlbum object contains properties of an album
    $albumId = $createdAlbum->getId();
    $productUrl = $createdAlbum->getProductUrl();
    // coverPhotoBaseUrl shouldn't be used as is. Append parameters to base URLs before use
    $albumCoverImage = $createdAlbum->getCoverPhotoBaseUrl() . '=w2048-h1024';
    $isWriteable = $createdAlbum->getIsWriteable();
} catch (\Google\ApiCore\ApiException $e) {
    // Handle error
}
    

Adding media items to an album

You can add media items from the user's Google Photos library to an album by calling albums.batchAddMediaItems. Media items are added to the end of the album in the order given in this call.

The entire request will fail if an invalid media item or album is specified. Partial success is not supported.

Each album can contain up to 20,000 media items. Requests to add more items that would exceed this limit will fail.

Note that you can only add media items that have been uploaded by your application to albums that your application has created. Media items must also be in the user's library. For albums that are shared, they must either be owned by the user or the user must be a collaborator who has already joined the album.

To add media items to an album, call albums.batchAddMediaItems with the identifiers of the media items and the album.

REST

Here is a header for a POST request:

POST https://photoslibrary.googleapis.com/v1/albums/ALBUM_ID:batchAddMediaItems
Content-type: application/json
Authorization: Bearer OAUTH2_TOKEN

The request body looks like this:

{
   "mediaItemIds": [
     "MEDIA_ITEM_ID",
     "ANOTHER_MEDIA_ITEM_ID",
     ...
   ]
}

If successful, the response returns an empty JSON response and the HTTP Success status.

Java

try {
  // List of media item IDs to add
  List<String> mediaItemIds = Arrays
      .asList("MEDIA_ITEM_ID", "ANOTHER_MEDIA_ITEM_ID");

  // ID of the album to add media items to
  String albumId = "ALBUM_ID";

  // Add all given media items to the album
  photosLibraryClient.batchAddMediaItemsToAlbum(albumId, mediaItemIds);

} catch (ApiException e) {
  // An exception is thrown if the media items could not be added
}
    

PHP

try {

    // List of media item IDs to add
    $mediaItemIds = ["MEDIA_ITEM_ID", "ANOTHER_MEDIA_ITEM_ID"];

    // ID of the album to add media items to
    $albumId = "ALBUM_ID";

    // Add all given media items to the album
    $response = $photosLibraryClient->batchAddMediaItemsToAlbum($albumId, $mediaItemIds);

} catch (\Google\ApiCore\ApiException $e) {
    // Handle Error
}
    

Removing media items from an album

You can remove media items that you have added from an album by calling albums.batchRemoveMediaItems.

The entire request will fail if invalid media items are specified. Partial success is not supported.

Note that you can only remove media items that your application has added to an album or that have been created in an album as part of an upload. For albums that are shared, you can only remove items added by other collaborators if you are acting on behalf of the owner of the album.

To remove media items from an album, call albums.batchRemoveMediaItems with the identifiers of the media items and the album.

REST

Here is a header for a POST request:

POST https://photoslibrary.googleapis.com/v1/albums/ALBUM_ID:batchRemoveMediaItems
Content-type: application/json
Authorization: Bearer OAUTH2_TOKEN

The request body looks like this:

{
   "mediaItemIds": [
     "MEDIA_ITEM_ID",
     "ANOTHER_MEDIA_ITEM_ID",
     ...
   ]
}

If successful, the response returns an empty JSON response and the HTTP Success status.

Java

try {
  // List of media item IDs to remove
  List<String> mediaItemIds = Arrays
      .asList("MEDIA_ITEM_ID", "ANOTHER_MEDIA_ITEM_ID");

  // ID of the album to remove media items from
  String albumId = "ALBUM_ID";

  // Remove all given media items from the album
  photosLibraryClient.batchRemoveMediaItemsFromAlbum(albumId, mediaItemIds);

} catch (ApiException e) {
  // An exception is thrown if the media items could not be removed
}
    

PHP

try {

    // List of media item IDs to remove
    $mediaItemIds = ["MEDIA_ITEM_ID", "ANOTHER_MEDIA_ITEM_ID"];

    // ID of the album to remove media items from
    $albumId = "ALBUM_ID";

    // Remove all given media items from the album
    $response = $photosLibraryClient->batchRemoveMediaItemsFromAlbum($albumId, $mediaItemIds);

} catch (\Google\ApiCore\ApiException $e) {
    // Handle Error
}