Access Google Photo API with Python using google-api-python-client

后端 未结 4 2100
轻奢々
轻奢々 2021-02-04 15:46

According to Google API Client Libraries page it is possible to access the Google Photos API using the python client library, but after installing it using pip install -t

4条回答
  •  不要未来只要你来
    2021-02-04 16:17

    The API is a bit less capable than indicated in the example above, it doesn't support "fields". But it does work:

    from googleapiclient.discovery import build
    from httplib2 import Http
    from oauth2client import file, client, tools
    SCOPES = 'https://www.googleapis.com/auth/photoslibrary.readonly'
    
    store = file.Storage('token-for-google.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('client_id.json', SCOPES)
        creds = tools.run_flow(flow, store)
    gdriveservice = build('photoslibrary', 'v1', http=creds.authorize(Http()))
    
    results = gdriveservice.albums().list(
        pageSize=10).execute()
    items = results.get('albums', [])
    for item in items:
            print(u'{0} ({1})'.format(item['title'].encode('utf8'), item['id']))
    

提交回复
热议问题