Searches for media items in a user's Google Photos library. If no filters are set, then all media items in the user's library are returned. If an album is set, all media items in the specified album are returned. If filters are specified, media items that match the filters from the user's library are listed. If you set both the album and the filters, the request results in an error.

Scopes

You will need authorization for at least one of the following scopes to make a valid call:

  • https://www.googleapis.com/auth/photoslibrary
  • https://www.googleapis.com/auth/photoslibrary.readonly
  • https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata

If unset, the scope for this method defaults to https://www.googleapis.com/auth/photoslibrary. You can set the scope for this method like this: photoslibrary1 --scope <scope> media-items search ...

Required Request Value

The request value is a data-structure with various fields. Each field may be a simple scalar or another data-structure. In the latter case it is advised to set the field-cursor to the data-structure's field to specify values more concisely.

For example, a structure like this:

SearchMediaItemsRequest:
  album-id: string
  filters:
    content-filter:
      excluded-content-categories: [string]
      included-content-categories: [string]
    exclude-non-app-created-data: boolean
    feature-filter:
      included-features: [string]
    include-archived-media: boolean
    media-type-filter:
      media-types: [string]
  order-by: string
  page-size: integer
  page-token: string

can be set completely with the following arguments which are assumed to be executed in the given order. Note how the cursor position is adjusted to the respective structures, allowing simple field names to be used most of the time.

  • -r . album-id=dolore
    • Identifier of an album. If populated, lists all media items in specified album. Can't set in conjunction with any filters.
  • filters.content-filter excluded-content-categories=dolore
    • The set of categories which are not to be included in the media item search results. The items in the set are ORed. There's a maximum of 10 excludedContentCategories per request.
    • Each invocation of this argument appends the given value to the array.
  • included-content-categories=voluptua.

    • The set of categories to be included in the media item search results. The items in the set are ORed. There's a maximum of 10 includedContentCategories per request.
    • Each invocation of this argument appends the given value to the array.
  • .. exclude-non-app-created-data=false

    • If set, the results exclude media items that were not created by this app. Defaults to false (all media items are returned). This field is ignored if the photoslibrary.readonly.appcreateddata scope is used.
  • feature-filter included-features=lorem

    • The set of features to be included in the media item search results. The items in the set are ORed and may match any of the specified features.
    • Each invocation of this argument appends the given value to the array.
  • .. include-archived-media=true

    • If set, the results include media items that the user has archived. Defaults to false (archived media items aren't included).
  • media-type-filter media-types=no

    • The types of media items to be included. This field should be populated with only one media type. If you specify multiple media types, it results in an error.
    • Each invocation of this argument appends the given value to the array.
  • ... order-by=est

    • An optional field to specify the sort order of the search results. The orderBy field only works when a dateFilter is used. When this field is not specified, results are displayed newest first, oldest last by their creationTime. Providing MediaMetadata.creation_time displays search results in the opposite order, oldest first then newest last. To display results newest first then oldest last, include the desc argument as follows: MediaMetadata.creation_time desc. The only additional filters that can be used with this parameter are includeArchivedMedia and excludeNonAppCreatedData. No other filters are supported.
  • page-size=74
    • Maximum number of media items to return in the response. Fewer media items might be returned than the specified number. The default pageSize is 25, the maximum is 100.
  • page-token=sed
    • A continuation token to get the next page of the results. Adding this to the request returns the rows after the pageToken. The pageToken should be the value returned in the nextPageToken parameter in the response to the searchMediaItems request.

About Cursors

The cursor position is key to comfortably set complex nested structures. The following rules apply:

  • The cursor position is always set relative to the current one, unless the field name starts with the . character. Fields can be nested such as in -r f.s.o .
  • The cursor position is set relative to the top-level structure if it starts with ., e.g. -r .s.s
  • You can also set nested fields without setting the cursor explicitly. For example, to set a value relative to the current cursor position, you would specify -r struct.sub_struct=bar.
  • You can move the cursor one level up by using ... Each additional . moves it up one additional level. E.g. ... would go three levels up.

Optional Output Flags

The method's return value a JSON encoded structure, which will be written to standard output by default.

  • -o out
    • out specifies the destination to which to write the server's result to. It will be a JSON-encoded structure. The destination may be - to indicate standard output, or a filepath that is to contain the received bytes. If unset, it defaults to standard output.

Optional General Properties

The following properties can configure any call, and are not specific to this method.

  • -p $-xgafv=string

    • V1 error format.
  • -p access-token=string

    • OAuth access token.
  • -p alt=string

    • Data format for response.
  • -p callback=string

    • JSONP
  • -p fields=string

    • Selector specifying which fields to include in a partial response.
  • -p key=string

    • API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
  • -p oauth-token=string

    • OAuth 2.0 token for the current user.
  • -p pretty-print=boolean

    • Returns response with indentations and line breaks.
  • -p quota-user=string

    • Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
  • -p upload-type=string

    • Legacy upload protocol for media (e.g. "media", "multipart").
  • -p upload-protocol=string

    • Upload protocol for media (e.g. "raw", "multipart").