Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

from os.path import join, dirname
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(join(dirname(__file__), 'token-for-google.json'))
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets(join(dirname(__file__), 'client_id.json', SCOPES))
    creds = tools.run_flow(flow, store)
google_photos = build('photoslibrary', 'v1', http=creds.authorize(Http()))

day, month, year = ('0', '6', '2019')  # 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 = google_photos.mediaItems().search(
            body={"filters":  {"dateFilter": {"dates": [{"day": day, "month": month, "year": year}]}},
                  "pageSize": 10, "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', [])
    nextpagetoken = results.get('nextPageToken', '')
    for item in items:
            print(f"{item['filename']} {item['mimeType']} '{item.get('description', '- -')}'"
                      f" {item['mediaMetadata']['creationTime']}
URL: {item['productUrl']}")
Comment

PREVIOUS NEXT
Code Example
Python :: numpy shape 
Python :: get_or_create in django 
Python :: pandas create dataframe from multiple dictionaries 
Python :: remove list from list python 
Python :: how to add string in csv in python 
Python :: PySimpleGUI all elements 
Python :: get variable from function python 
Python :: python pytest no coverage on failure 
Python :: capitalise texts 
Python :: how to use replace in python 
Python :: how to display items on a list on new lines python 
Python :: python create sqlite db file 
Python :: Dictionary Cache 
Python :: find the difference of strings in python 
Python :: find a character in a string python last 
Python :: golang get started 
Python :: Set path for another directory 
Python :: aiohttps 
Python :: python list pop 
Python :: python for loop practice problems 
Python :: accessing a variable from outside the function in python 
Python :: extract images from pdf 
Python :: how to put space in between list item in python 
Python :: pytest create server 
Python :: python tex box 
Python :: repl.it install packages python 
Python :: print("hello world") 
Python :: python list append 
Python :: optional parameter in python 
Python :: Find Factors of a Number Using Function 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =