pythongoogle-photos-api

filter based media search with google photos API (python)


I'm trying to use the mediaItems().search() method, using the following body:

body = {
        "pageToken": page_token if page_token != "" else "",
        "pageSize": 100,
        "filters": {
            "contentFilter": {
                "includedContentCategories": {"LANDSCAPES","CITYSCAPES"}
            }
        },
        "includeArchiveMedia": include_archive
    }

but the problem is that the set {"LANDSCAPES","CITYSCAPES"} should actually be a set of enums (as in Java enums), and not strings as ive written. this is specified in the API: (https://developers.google.com/photos/library/reference/rest/v1/albums)

ContentFilter - This filter allows you to return media items based on the content type.

JSON representation

{
  "includedContentCategories": [
    enum (ContentCategory)
  ],
  "excludedContentCategories": [
    enum (ContentCategory)
  ]
}

is there a proper way of solving this in python?


Solution

  • Modification points:

    When above points are reflected to your script, it becomes as follows.

    Modified script:

    body = {
        # "albumId": album_id,  # <--- removed
        "pageToken": page_token if page_token != "" else "",
        "pageSize": 100,
        "filters": {
            "contentFilter": {
                "includedContentCategories": ["LANDSCAPES", "CITYSCAPES"]
            },
            "includeArchivedMedia": include_archive
        }
    }
    

    Reference: