### Simple HTTP GET Request (No Fields Parameter) Source: https://developers.google.com/photos/library/guides/performance-tips This example demonstrates a basic HTTP GET request to a demo API without specifying any fields. It will return the full resource. ```http https://www.googleapis.com/demo/v1 ``` -------------------------------- ### Set Album Position to Start (Java) Source: https://developers.google.com/photos/library/guides/add-enrichments Use AlbumPositionFactory to create a position object for the start of the album in Java. ```java AlbumPosition albumPosition = AlbumPositionFactory.createFirstInAlbum(); ``` -------------------------------- ### Full Resource Response Example Source: https://developers.google.com/photos/overview/performance-tips An example of a full resource response from a demo API, including numerous fields. This demonstrates the amount of data that can be returned without using the `fields` parameter. ```json { "kind": "demo", ... "items": [ { "title": "First title", "comment": "First comment.", "characteristics": { "length": "short", "accuracy": "high", "followers": ["Jo", "Will"], }, "status": "active", ... }, { "title": "Second title", "comment": "Second comment.", "characteristics": { "length": "long", "accuracy": "medium" "followers": [ ], }, "status": "pending", ... }, ... ] } ``` -------------------------------- ### Full Resource Response Example Source: https://developers.google.com/photos/library/guides/performance-tips This is an example of a full resource response from the demo API, including various fields and nested objects. It is shown for comparison with partial responses. ```json { "kind": "demo", ... "items": [ { "title": "First title", "comment": "First comment.", "characteristics": { "length": "short", "accuracy": "high", "followers": ["Jo", "Will"], }, "status": "active", ... }, { "title": "Second title", "comment": "Second comment.", "characteristics": { "length": "long", "accuracy": "medium" "followers": [ ], }, "status": "pending", ... }, ... ] } ``` -------------------------------- ### Partial Resource Response Example Source: https://developers.google.com/photos/library/guides/performance-tips This is an example of a partial response received after using the `fields` parameter in the request. It contains only the 'kind' and specified 'items' fields. ```json { "kind": "demo", "items": [{ "title": "First title", "characteristics": { "length": "short" } }, { "title": "Second title", "characteristics": { "length": "long" } }, ... ] } ``` -------------------------------- ### Set Album Position to Start (PHP) Source: https://developers.google.com/photos/library/guides/add-enrichments Create an AlbumPosition object and set its position to FIRST_IN_ALBUM in PHP. ```php $albumPosition = new AlbumPosition(); $albumPosition->setPosition(PositionType::FIRST_IN_ALBUM); ``` -------------------------------- ### Set Album Position to Start (REST) Source: https://developers.google.com/photos/library/guides/add-enrichments Use this JSON structure to set the album position to the start of the album. ```json { "position": "FIRST_IN_ALBUM", } ``` -------------------------------- ### get Source: https://developers.google.com/photos/library/reference/rest Returns the app created media item for the specified media item identifier. ```APIDOC ## GET /v1/mediaItems/{mediaItemId} ### Description Returns the app created media item for the specified media item identifier. ### Method GET ### Endpoint /v1/mediaItems/{mediaItemId} ### Parameters #### Path Parameters - **mediaItemId** (string) - Required - The identifier of the media item to retrieve. ``` -------------------------------- ### Initialize Resumable Upload (Single Request) Source: https://developers.google.com/photos/library/guides/resumable-uploads Start a resumable upload session for a single request. This initializes the upload and provides the upload URL and chunk granularity. ```http POST https://photoslibrary.googleapis.com/v1/uploads HTTP/1.1 Content-Length: 0 X-Goog-Upload-Command: start X-Goog-Upload-Content-Type: image/jpeg X-Goog-Upload-Protocol: resumable X-Goog-Upload-Raw-Size: 3039417 [no body] ``` -------------------------------- ### get Source: https://developers.google.com/photos/library/reference/rest/v1/albums Returns the app created album based on the specified `albumId`. ```APIDOC ## `get` Returns the app created album based on the specified `albumId`. ``` -------------------------------- ### Sort media items by creation time (oldest first) Source: https://developers.google.com/photos/library/guides/apply-filters This example demonstrates how to filter media items by date and sort them in ascending order (oldest first). ```REST { "filters": { "dateFilter": { "dates": [ { "year": 2017 } ] } }, "orderBy": "MediaMetadata.creation_time" } ``` -------------------------------- ### Initiate Resumable Upload Session Source: https://developers.google.com/photos/library/guides/resumable-uploads Send a POST request to start a resumable upload session. Ensure all required headers are set, including content type and raw file size. ```http POST https://photoslibrary.googleapis.com/v1/uploads Authorization: Bearer oauth2-token Content-Length: 0 X-Goog-Upload-Command: start X-Goog-Upload-Content-Type: mime-type X-Goog-Upload-Protocol: resumable X-Goog-Upload-Raw-Size: bytes-of-file ``` -------------------------------- ### HTTP Request for mediaItems.list Source: https://developers.google.com/photos/ambient/reference/rest/v1/mediaItems/list This is the base HTTP GET request to list media items. Ensure you include the required `deviceId` query parameter. ```http GET https://photosambient.googleapis.com/v1/mediaItems ``` -------------------------------- ### Create Session Source: https://developers.google.com/photos/picker/reference/rest Generates a new session, which is a container for a user's photo picking activity. This session is required before users can start selecting media. ```APIDOC ## POST /v1/sessions ### Description Generates a new session during which the user can pick photos and videos for third-party access. ### Method POST ### Endpoint /v1/sessions ``` -------------------------------- ### Example Response Structure for Listing Media Items Source: https://developers.google.com/photos/library/guides/list This JSON structure represents a paginated response when listing media items. The `nextPageToken` indicates if more results are available. ```json { "mediaItem": [ … ], "nextPageToken": "next-page-token" } ``` -------------------------------- ### Poll Session Status - GET Request Source: https://developers.google.com/photos/picker/guides/sessions Use this GET request to poll the status of a session. Check the response for `mediaItemsSet` to determine if the user has finished selecting media. ```http GET https://photoslibrary.googleapis.com/v1/sessions/{sessionId} ``` -------------------------------- ### batchGet Source: https://developers.google.com/photos/library/reference/rest Returns the list of app created media items for the specified media item identifiers. ```APIDOC ## GET /v1/mediaItems:batchGet ### Description Returns the list of app created media items for the specified media item identifiers. ### Method GET ### Endpoint /v1/mediaItems:batchGet ``` -------------------------------- ### List Media Items Source: https://developers.google.com/photos/ambient/guides/media-items Once `mediaSourcesSet` is true for a device, you can begin fetching the media items selected by the user. Make a GET request to the `mediaItems.list` endpoint and handle pagination if necessary. The response contains an array of `AmbientMediaItem` objects, each with details like `id`, `creationTime`, and `mediaFile`. ```APIDOC ## List Media Items Once `mediaSourcesSet` is `true` for a device, you can begin fetching the media items selected by the user. 1. **Use the `mediaItems.list` endpoint:** Make a GET request to `https://photosambient.googleapis.com/v1/mediaItems`, providing the `deviceId` in the path. 2. **Handle pagination (if necessary):** The response may be paginated. Use the `pageSize` parameter to specify the maximum number of items to return, and the `pageToken` from a previous response to retrieve subsequent pages of results. 3. **Process the media items:** The response will contain an array of `AmbientMediaItem` objects, each representing a selected media item. These objects include essential details like: * `id`: The unique identifier for the media item. * `creationTime`: The timestamp when the media item was created. * `mediaFile`: An object containing details to access the actual content. The `mediaFile` field includes the `baseUrl`. This `baseUrl` is what you will use to construct URLs to access the media item's content at various resolutions or formats. ``` -------------------------------- ### Date Source: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search Represents a whole calendar date. Set `day` to 0 when only the month and year are significant, for example, all of December 2018. Set `day` and `month` to 0 if only the year is significant, for example, the entire of 2018. Set `year` to 0 when only the day and month are significant, for example, an anniversary or birthday. Unsupported: Setting all values to 0, only `month` to 0, or both `day` and `year` to 0 at the same time. ```APIDOC ## Date Represents a whole calendar date. Set `day` to 0 when only the month and year are significant, for example, all of December 2018. Set `day` and `month` to 0 if only the year is significant, for example, the entire of 2018. Set `year` to 0 when only the day and month are significant, for example, an anniversary or birthday. Unsupported: Setting all values to 0, only `month` to 0, or both `day` and `year` to 0 at the same time. ### JSON Representation ```json { "year": "integer", "month": "integer", "day": "integer" } ``` ### Fields * `year` (integer): Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year. * `month` (integer): Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day. * `day` (integer): Day of month. Must be from 1 to 31 and valid for the year and month, or 0 if specifying a year/month where the day isn't significant. ``` -------------------------------- ### Enable gzip compression with HTTP headers Source: https://developers.google.com/photos/library/guides/performance-tips Set the `Accept-Encoding` header to `gzip` and modify the `User-Agent` to include `gzip` to receive gzip-encoded responses. This reduces bandwidth consumption at the cost of additional CPU time for decompression. ```http Accept-Encoding: gzip User-Agent: my program (gzip) ``` -------------------------------- ### Get a single media item Source: https://developers.google.com/photos/library/guides/access-media-items Use this GET request to retrieve a specific media item by its ID. The response includes details like ID, description, URLs, and metadata specific to photos or videos. ```http GET https://photoslibrary.googleapis.com/v1/mediaItems/media-item-id Content-type: application/json Authorization: Bearer oauth2-token ``` ```json { "id": "media-item-id", "description": "item-description", "productUrl": "url-to-open-in-google-photos", "baseUrl": "base-url_do-not-use-directly", "mimeType": "mime-type-of-media", "filename": "item-filename", "mediaMetadata": { "width": "media-item-width", "height": "media-item-height", "creationTime": "media-item-creation-time", "photo": { "cameraMake": "make-of-the-camera", "cameraModel": "model-of-the-camera", "focalLength": "focal-length-of-the-camera-lens", "apertureFNumber": "aperture-f-number-of-the-camera-lens", "isoEquivalent": "iso-of-the-camera", "exposureTime": "exposure-time-of-the-camera-aperture" } }, "contributorInfo": { "profilePictureBaseUrl": "profile-picture-base-url_do-not-use-directly", "displayName": "name-of-user" } } ``` ```json { "id": "media-item-id", "description": "item-description", "productUrl": "url-to-open-in-google-photos", "baseUrl": "base-url_do-not-use-directly", "mimeType": "mime-type-of-media", "filename": "item-filename", "mediaMetadata": { "width": "media-item-width", "height": "media-item-height", "creationTime": "media-item-creation-time", "video": { "cameraMake": "make-of-the-camera", "cameraModel": "model-of-the-camera", "fps": "frame-rate-of-the-video", "status": "READY" }, }, "contributorInfo": { "profilePictureBaseUrl": "profile-picture-base-url_do-not-use-directly", "displayName": "name-of-user" } } ``` -------------------------------- ### Create Media Items Source: https://developers.google.com/photos/library/guides/upload-media This endpoint allows you to create one or more media items in a user's library. You provide a list of `newMediaItems`, each containing an upload token and an optional description. For optimal performance, batch multiple media items into a single request. ```APIDOC ## POST mediaItems:batchCreate ### Description Creates one or more media items in a user's library using provided upload tokens. ### Method POST ### Endpoint https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate ### Request Body - **newMediaItems** (array) - Required - A list of media items to create. Each item should contain a `description` and a `simpleMediaItem` with `fileName` and `uploadToken`. - **description** (string) - Optional - A user-created description for the media item (max 1000 characters). - **simpleMediaItem** (object) - Required - Contains details for the media item. - **fileName** (string) - Required - The name of the file. - **uploadToken** (string) - Required - The upload token obtained from a previous upload. ### Request Example (Basic) ```json { "newMediaItems": [ { "description": "item-description", "simpleMediaItem": { "fileName": "filename", "uploadToken": "upload-token" } } ] } ``` ### Request Example (With Album Information) ```json { "albumId": "album-id", "newMediaItems": [ { "description": "item-description", "simpleMediaItem": { "fileName": "filename", "uploadToken": "upload-token" } } ], "albumPosition": { "position": "after-media-item", "relativeMediaItemId": "media-item-id" } } ``` ### Response #### Success Response (200 OK) Returns a list of results for each media item creation attempt. - **newMediaItemResults** (array) - Contains the result for each media item. - **uploadToken** (string) - The upload token used for the request. - **status** (object) - The status of the creation attempt. - **message** (string) - A message describing the status (e.g., "Success"). - **code** (integer) - An error code if the creation failed. - **mediaItem** (object) - If successful, contains details of the created media item. - **id** (string) - The unique identifier for the media item. - **description** (string) - The description of the media item. - **productUrl** (string) - The URL to the media item in Google Photos. - **mimeType** (string) - The MIME type of the media item. - **mediaMetadata** (object) - Metadata about the media. - **width** (string) - Width of the media in pixels. - **height** (string) - Height of the media in pixels. - **creationTime** (string) - Timestamp of when the media was created. - **photo** (object) - Contains photo-specific metadata. - **filename** (string) - The original filename. #### Partial Success Response (207 MULTI-STATUS) Returned if some media items could not be created. ### Response Example ```json { "newMediaItemResults": [ { "uploadToken": "upload-token", "status": { "message": "Success" }, "mediaItem": { "id": "media-item-id", "description": "item-description", "productUrl": "https://photos.google.com/photo/photo-path", "mimeType": "mime-type", "mediaMetadata": { "width": "media-width-in-px", "height": "media-height-in-px", "creationTime": "creation-time", "photo": {} }, "filename": "filename" } }, { "uploadToken": "upload-token", "status": { "code": 13, "message": "Internal error" } } ] } ``` ``` -------------------------------- ### HTTP GET Request with Fields Parameter Source: https://developers.google.com/photos/library/guides/performance-tips This HTTP GET request utilizes the `fields` parameter to request only specific fields ('kind', 'items(title,characteristics/length)') from the demo API, significantly reducing the response size. ```http https://www.googleapis.com/demo/v1?**fields=kind,items(title,characteristics/length)** ``` -------------------------------- ### get Source: https://developers.google.com/photos/picker/reference/rest/v1/sessions Retrieves information about the specified session. ```APIDOC ## get ### Description Retrieves information about the specified session. ### Method GET ### Endpoint /v1/sessions/{sessionId} ### Parameters #### Path Parameters - **sessionId** (string) - Required - The unique identifier of the session to retrieve. ### Response #### Success Response (200) - **PickingSession** (object) - Information about the photo selection session. - **id** (string) - The unique identifier for the session. - **pickerUri** (string) - The URI to direct users to Google Photos for media selection. - **expireTime** (string) - The timestamp when the session expires. - **pollingConfig** (object) - Configuration for polling the session status. - **pollInterval** (string) - The interval at which to poll for updates. - **timeoutIn** (string) - The total timeout for polling. - **mediaItemsSet** (boolean) - Indicates if media items have been selected. #### Response Example { "example": "{ \"id\": \"session-123\", \"pickerUri\": \"https://photos.google.com/picker?sessionId=session-123\", \"expireTime\": \"2025-10-06T10:00:00Z\", \"pollingConfig\": { \"pollInterval\": \"5s\", \"timeoutIn\": \"1m\" }, \"mediaItemsSet\": false }" } ``` -------------------------------- ### Filtering by Date Ranges Source: https://developers.google.com/photos/library/guides/apply-filters Use date ranges to filter media items within a specified period. Both a start date and an end date must be provided, and they must use the same format. The range is inclusive of the start and end dates. ```APIDOC ## Filtering by Date Ranges ### Description Filter media items within a specified period using date ranges. Both a start date and an end date must be provided, and they must use the same format. The range is inclusive of the start and end dates. ### Method Not applicable (This describes a filter configuration, not a direct API call). ### Endpoint Not applicable (This describes a filter configuration, not a direct API call). ### Parameters #### Query Parameters - **filters** (object) - Required - An object containing various filter criteria, including `dateFilter`. - **dateFilter** (object) - Optional - An object to specify date-based filtering. - **ranges** (array) - Optional - An array of date range objects to filter by. - **startDate** (object) - Required - The start date of the range. - **year** (integer) - Optional - The year of the start date. - **month** (integer) - Optional - The month of the start date (1-12). - **day** (integer) - Optional - The day of the month (1-31). - **endDate** (object) - Required - The end date of the range. - **year** (integer) - Optional - The year of the end date. - **month** (integer) - Optional - The month of the end date (1-12). - **day** (integer) - Optional - The day of the month (1-31). ### Request Example ```json { "filters": { "dateFilter": { "ranges": [ { "startDate": { "year": 2014, "month": 6, "day": 12 }, "endDate": { "year": 2014, "month": 7, "day": 13 } } ] } } } ``` ### Response #### Success Response (200) - **mediaItems** (array) - A list of media items matching the filter criteria. - **nextPageToken** (string) - Token to retrieve the next page of results. #### Response Example ```json { "mediaItems": [ { "id": "string", "description": "string", "productUrl": "string", "baseUrl": "string", "mimeType": "string", "mediaMetadata": {}, "filename": "string" } ], "nextPageToken": "string" } ``` ``` -------------------------------- ### list Source: https://developers.google.com/photos/picker/reference/rest/v1/mediaItems Returns a list of media items picked by the user during the specified session. ```APIDOC ## list ### Description Returns a list of media items picked by the user during the specified session. ### Method GET ### Endpoint /v1/mediaItems ### Parameters #### Query Parameters - **sessionId** (string) - Required - The session ID for which to retrieve media items. ### Response #### Success Response (200) - **mediaItems** (array) - A list of media items. - **id** (string) - The unique identifier for the media item. - **createTime** (string) - The timestamp when the media item was created. - **type** (string) - The type of the media item (e.g., 'PHOTO', 'VIDEO'). - **mediaFile** (object) - Information about the media file. - **baseUrl** (string) - The base URL for downloading the media file. - **mimeType** (string) - The MIME type of the media file. - **filename** (string) - The name of the media file. - **mediaFileMetadata** (object) - Metadata about the media file. - **width** (integer) - The width of the media item in pixels. - **height** (integer) - The height of the media item in pixels. - **photo** (object) - Photo-specific metadata. - **focalLength** (number) - Focal length of the camera lens. - **apertureFNumber** (number) - Aperture f number of the camera lens. - **isoEquivalent** (integer) - ISO of the camera. - **exposureTime** (string) - Exposure time of the camera aperture. - **video** (object) - Video-specific metadata. - **fps** (number) - Frame rate of the video. - **processingStatus** (string) - Processing status of the video (e.g., 'PROCESSING', 'READY', 'FAILED'). ### Response Example ```json { "mediaItems": [ { "id": "media-item-1", "createTime": "2023-10-27T10:00:00Z", "type": "PHOTO", "mediaFile": { "baseUrl": "https://photos.google.com/media/some_id", "mimeType": "image/jpeg", "filename": "photo.jpg", "mediaFileMetadata": { "width": 1920, "height": 1080, "photo": { "focalLength": 50, "apertureFNumber": 1.8, "isoEquivalent": 100, "exposureTime": "1/125s" } } } }, { "id": "media-item-2", "createTime": "2023-10-27T11:00:00Z", "type": "VIDEO", "mediaFile": { "baseUrl": "https://photos.google.com/media/some_other_id", "mimeType": "video/mp4", "filename": "video.mp4", "mediaFileMetadata": { "width": 1280, "height": 720, "video": { "fps": 30, "processingStatus": "READY" } } } } ] } ``` ``` -------------------------------- ### Get Session Source: https://developers.google.com/photos/picker/reference/rest/v1/sessions Retrieves the details of a specific session. ```APIDOC ## GET /v1/sessions/{session_id} ### Description Retrieves the details of a specific session. ### Method GET ### Endpoint /v1/sessions/{session_id} ### Parameters #### Path Parameters - **session_id** (string) - Required - The identifier of the session to retrieve. ### Response #### Success Response (200) - **id** (string) - Output only. The Google-generated identifier for this session. - **pickerUri** (string) - Output only. The URI used to redirect the user to Google Photos. - **pollingConfig** (object) - Output only. The recommended configuration that applications should use while polling `sessions.get`. - **expireTime** (string (Timestamp format)) - Output only. Time when access to this session will expire. - **pickingConfig** (object) - Optional. Photo-picking configuration for the user's picking experience during this session. - **mediaItemsSet** (boolean) - Output only. If true, media items have been picked for this session. ``` -------------------------------- ### batchCreate Source: https://developers.google.com/photos/library/reference/rest Creates one or more media items in a user's Google Photos library. ```APIDOC ## POST /v1/mediaItems:batchCreate ### Description Creates one or more media items in a user's Google Photos library. ### Method POST ### Endpoint /v1/mediaItems:batchCreate ``` -------------------------------- ### List Media Items Source: https://developers.google.com/photos/ambient/reference/rest/v1/mediaItems Returns a list of ambient media items from user-configured media sources for the specified device. ```APIDOC ## GET /v1/mediaItems ### Description Returns a list of ambient media items from user-configured media sources for the specified device. ### Method GET ### Endpoint /v1/media আইটেম ``` -------------------------------- ### Get Ambient Device Source: https://developers.google.com/photos/ambient/reference/rest Retrieves information about the specified device. ```APIDOC ## GET /v1/devices/{deviceId} ### Description Retrieves information about the specified device. ### Method GET ### Endpoint /v1/devices/{deviceId} ### Parameters #### Path Parameters - **deviceId** (string) - Required - The ID of the device to retrieve. ``` -------------------------------- ### Get multiple media items by ID Source: https://developers.google.com/photos/library/guides/access-media-items Use this GET request to retrieve multiple media items by their IDs. The request can include up to 50 unique media item IDs. The response contains a list of results, each being either a `MediaItem` or a `Status` object indicating an error. ```http GET https://photoslibrary.googleapis.com/v1/mediaItems:batchGet?mediaItemIds=media-item-id&mediaItemIds=another-media-item-id&mediaItemIds=incorrect-media-item-id Content-type: application/json Authorization: Bearer oauth2-token ``` ```json { "mediaItemResults": [ { "mediaItem": { "id": "media-item-id", ... } }, { "mediaItem": { "id": "another-media-item-id", ... } }, { "status": { "code": 3, "message": "Invalid media item ID." } } ] } ``` -------------------------------- ### create Source: https://developers.google.com/photos/library/reference/rest/v1/albums Creates an album in a user's Google Photos library. ```APIDOC ## `create` Creates an album in a user's Google Photos library. ``` -------------------------------- ### Get Session Source: https://developers.google.com/photos/picker/reference/rest Retrieves information about a specific session, such as its status or associated metadata. ```APIDOC ## GET /v1/sessions/{sessionId} ### Description Retrieves information about the specified session. ### Method GET ### Endpoint /v1/sessions/{sessionId} #### Path Parameters - **sessionId** (string) - Required - The identifier of the session to retrieve. ``` -------------------------------- ### Response for mediaItems.batchCreate Source: https://developers.google.com/photos/library/guides/upload-media This JSON response shows the result of a `mediaItems.batchCreate` call. It includes the status for each media item, with details for successfully created items and error information for failed ones. ```json { "newMediaItemResults": [ { "uploadToken": "upload-token", "status": { "message": "Success" }, "mediaItem": { "id": "media-item-id", "description": "item-description", "productUrl": "https://photos.google.com/photo/photo-path", "mimeType": "mime-type", "mediaMetadata": { "width": "media-width-in-px", "height": "media-height-in-px", "creationTime": "creation-time", "photo": {} }, "filename": "filename" } }, { "uploadToken": "upload-token", "status": { "code": 13, "message": "Internal error" } } ] } ``` -------------------------------- ### DateRange Structure Source: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search Defines a range of dates for filtering, including a start and end date. Both dates must use the same format. ```json { "startDate": { object (Date) }, "endDate": { object (Date) } } ``` -------------------------------- ### Create a new album - Response Source: https://developers.google.com/photos/library/guides/manage-albums A successful album creation returns an album object, which includes its ID, title, and product URL. Store the album ID for future use. ```json { "productUrl": "album-product-url", "id": "album-id", "title": "album-title", "isWriteable": "whether-you-can-write-to-this-album" } ``` -------------------------------- ### Create Media Items and Add to an Album Source: https://developers.google.com/photos/library/guides/upload-media This JSON body demonstrates how to create media items and specify an `albumId` and `albumPosition` to insert them at a specific location within an album. ```json { "albumId": "album-id", "newMediaItems": [ { "description": "item-description", "simpleMediaItem": { "fileName": "filename", "uploadToken": "upload-token" } } , ... ], "albumPosition": { "position": "after-media-item", "relativeMediaItemId": "media-item-id" } } ``` -------------------------------- ### Add Map Enrichment to Album Source: https://developers.google.com/photos/library/reference/rest/v1/albums/addEnrichment Example of adding a map enrichment to an album. This specifies the center of the map and the zoom level. ```json { "newEnrichmentItem": { "mapEnrichment": { "center": { "latitude": 36.106944, "longitude": -112.112778 }, "zoom": 12 } }, "albumPosition": { "position": "AFTER_MEDIA_ITEM_ID", "relativeMediaItemId": "some_media_item_id" } } ``` -------------------------------- ### Pseudocode for Creating Media Items Source: https://developers.google.com/photos/library/guides/upload-media This pseudocode outlines the logic for creating media items in Google Photos. It details when to trigger the `batchCreate` call, how to manage upload tokens, and the process of handling parallel calls for different users. ```pseudocode // For each user, create media items once 50 upload tokens have been // saved, or no more uploads are left per user. WHEN uploadTokensQueue for user is >= 50 OR no more pending uploads for user // Calls can be made in parallel for different users, // but only make a single call per user at a time. START new thread for (this) user if there is no thread yet POP 50 uploadTokens from uploadTokensQueue for user CALL mediaItems.batchCreate with uploadTokens WAIT UNTIL batchCreate call has completed CHECK and HANDLE errors (retry as needed) DONE. ``` -------------------------------- ### Add Location Enrichment to Album Source: https://developers.google.com/photos/library/reference/rest/v1/albums/addEnrichment Example of adding a location enrichment to an album. This includes the location name and its latitude/longitude coordinates. ```json { "newEnrichmentItem": { "locationEnrichment": { "location": { "locationName": "Grand Canyon National Park", "latlng": { "latitude": 36.106944, "longitude": -112.112778 } } } }, "albumPosition": { "position": "AFTER_MEDIA_ITEM_ID", "relativeMediaItemId": "some_media_item_id" } } ``` -------------------------------- ### Session Response Structure Source: https://developers.google.com/photos/picker/guides/sessions This is an example of the response structure when polling a session. Key fields include `id`, `pickerUri`, `pollingConfig`, and `mediaItemsSet`. ```json { "id": string, "pickerUri": string, "pollingConfig": { object (PollingConfig) }, "mediaItemsSet": boolean } ``` -------------------------------- ### Search Media Items with Filters (Java) Source: https://developers.google.com/photos/library/guides/apply-filters Instantiate a `Filters` object, optionally setting content or date filters, and then use it in the `searchMediaItems` call. Handle potential `ApiException`. ```java try { // Create a new Filter object Filters filters = Filters.newBuilder() // .setContentFilter(...) // .setDateFilter(...) // ... .build(); // Specify the Filter object in the searchMediaItems call SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters); for (MediaItem item : response.iterateAll()) { // ... } } catch (ApiException e) { // Handle error } ``` -------------------------------- ### Create Location Enrichment (PHP) Source: https://developers.google.com/photos/library/guides/add-enrichments Create a new location object and set the name, latitude, and longitude of the location in PHP. Then use PhotosLibraryResourceFactory to create the enrichment item. ```php // Create a new location object and set the name, latitude, and longitude of the location $newLocation = new Location(); $newLocation->setLocationName("Australia"); $newLocation->setLatlng((new LatLng())->setLatitude(-21.197)->setLongitude(95.821)); $newEnrichmentItem = PhotosLibraryResourceFactory::newEnrichmentItemWithLocation($newLocation); ```