How to add positioning enrichment to media item in Google Photos API?

247 views Asked by At

Reading Google Photos API documentation on how to add position media items inside the album I can't understand what should be the request body. https://developers.google.com/photos/library/guides/add-enrichments#supported-positioning

I want to move mediaItem-1 to be before mediaItem-2 in album album-1. How my request body should look like?

POST https://photoslibrary.googleapis.com/v1/albums/album-1:addEnrichment
{
    "newEnrichmentItem": {
        enrichment-to-be-added // What goes here?
    },
    "albumPosition": {
        "position": "after-media-item",
        "relativeMediaItemId": "mediaItem-2"
    }
}

EDIT: I don't want to reupload a media item to the cloud, so there will be only one version of the same media item.

1

There are 1 answers

6
Ron M On

A position can only be specified when creating a media item or adding enrichments. Existing media items in an album can't be reorganized, so it's important to set the position of an item when it's being added.

Reference: https://developers.google.com/photos/library/guides/add-enrichments#intro-positions

The method you are using is for Album Enrichment.

Enrichment Types:

  1. Text enrichments

    A text enrichment is a plain text string that can be inserted to annotate the album.

  2. Location enrichments

    A location enrichment is a marker and the name of the place that can be inserted to annotate a location.

  3. Map enrichments

    A map enrichment is a map with a specified origin and destination that can be inserted in the album.

Additional References: https://developers.google.com/photos/library/reference/rest/v1/albums/addEnrichment?hl=en_US#request-body


Sample media item creation with position: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/batchCreate#request-body

{
  "albumId": string,
  "newMediaItems": [
    {
      object (NewMediaItem)
    }
  ],
  "albumPosition": {
    object (AlbumPosition)
  }
}

albumPosition

  • Position in the album where the media items are added. If not specified, the media items are added to the end of the album (as per the default value, that is, LAST_IN_ALBUM). The request fails if this field is set and the albumId is not specified. The request will also fail if you set the field and are not the owner of the shared album.

(UPDATE)

Workaround:

  1. Delete mediaItem-2 in album-1

  2. Create mediaItem-2 in album-1 with position parameter which will place mediaItem-2 after mediaItem-1 https://developers.google.com/photos/library/reference/rest/v1/AlbumPosition#PositionType


Your request body for create media item:

{
  "albumId": album-1,
  "newMediaItems": [
    {
      object (mediaItem-2)
    }
  ],
  "albumPosition": {
    "position": AFTER_MEDIA_ITEM.
    "relativeMediaItemId": mediaItem-1
  }
}