[Python] google photos API people tag

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I've been trying to find the "people" fields in the Google Photos API. I find it mentioned in some of the google AI listings, but that code never works to retrieve the people fields. What I'm wanting to do is retrieve the "people" face tags as recorded in the facial recognition. I'm simply wanting a list of all the "people/faces" recognized/named. The Google photos online does it and I'm just trying to do a similar thing to build a spreadsheet/list of names. The google Photo API resource doesn't mention the people tag, but it is included in the Takeout information as:

    "people": [{
    "name": "person1 name"
    }, {
    "name": "Person 2 name"
    }, {
    "name": "person 3 name "
    }],


    Has anyone been able to retrieve the people tags with the google photos API? I'm working in Python and have tried multiple things, but none work.

    last code sample:

    > day, month, year = ('0', '6', '1950') # Day or month may be 0 => full
    > month resp. year date_filter = [{"day": day, "month": month, "year":
    > year}] # No leading zeroes for day an month! nextpagetoken = 'Dummy'
    > while nextpagetoken != '':
    > nextpagetoken = '' if nextpagetoken == 'Dummy' else nextpagetoken
    > results = service.mediaItems().search(
    > body={"filters": {"dateFilter": {"dates": [{"day": day, "month": month, "year": year}]}},
    > "pageSize": 100, "pageToken": nextpagetoken}).execute()
    > # The default number of media items to return at a time is 25. The maximum pageSize is 100.
    > # items = results.get('mediaItems', [],fields='people')
    > items = results.get('mediaItems',[])
    > nextpagetoken = results.get('nextPageToken', '')
    > for item in items:
    > ## print(f"{item['filename']} {item['mimeType']} '{item.get('description', '- -')}'"
    > ## f" {item['mediaMetadata']['creationTime']}")
    > if 'people' in item:
    > for person in item['people']:
    > print(person['name'])


    The people tag is not found in item. So either I have the tag coded incorrectly or the people tag is not returned in the JSON. the response from the above is:

    python photo_list.py photoslibrary v1 service created successfully

    C:\mypython>

    if I add "fields='people'" to the call an error occurs saying the "people" tag is not valid. So I'm stuck with not knowing what causes the people tag is placed in the JSON on the mediatItems.list/batchget/search. Again i've tried 8-10 different calls and everything ends with the same 'no tag available' type message.

    Continue reading...

Compartilhe esta Página