I am having trouble extending the API calls required to list album ids to be able to list the items contained in the album. An example of what I have done to retrieve album ids appears below. Beyond that example, I include my attempt to extend this script to be able to list the items contained in a specific album.
from httplib2 import Http
from oauth2client import file, client, tools
from apiclient.discovery import build
SCOPES = 'https://www.googleapis.com/auth/photoslibrary.readonly'
store = file.storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('photoslibrary', 'v1', http=creds.authorize(Http()))
hasNextPageToken = False
nextPageToken = ""
results = service.albums().list(pageSize=10).execute()
if 'nextPageToken' in results:
hasNextPageToken = True
nextPageToken = results['nextPageToken']
for album in results['albums']:
albumId = album['id']
print(albumId)
Now, for the code that I am attempting to modify from the example above to be able to list the items in a given album defined by albumId
:
from httplib2 import Http
from oauth2client import file, client, tools
from apiclient.discovery import build
SCOPES = 'https://www.googleapis.com/auth/photoslibrary.readonly'
store = file.storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('photoslibrary', 'v1', http=creds.authorize(Http()))
hasNextPageToken = False
nextPageToken = ""
albumId = [albumIdFromPreviousStep]
results = service.mediaItems().search(pageSize=10,albumId=albumId).execute()
When I attempt to print the results
, I receive an error about receiving an unexpected keyword argument, albumId
.
The api call is formatted differently for search, it is https://photoslibrary.googleapis.com/v1/mediaItems:search
Is the error stemming from the : mediaItems:search
which invalidates the variable in Python? Or is it related to the fact that the search call is a POST rather than a GET? Or, something else?