このようなコード例の組み合わせを見つけてきました。しかし、維持されたライブラリ(google-auth)+完全な動作例はありません。google-api-python-client
サポートさoauth2client
れなくなりました ( https://github.com/googleapis/google-api-python-client/issues/651 )。
非推奨のライブラリを使用した実際の例を次に示しますが、API へのフル アクセスを許可する例をいくつか見てみたいと思います (現在、albumId による検索はこのライブラリでは機能しません)。
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# Setup the Photo v1 API
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()))
# Call the Photo v1 API
results = service.albums().list(
pageSize=10, fields="nextPageToken,albums(id,title)").execute()
items = results.get('albums', [])
if not items:
print('No albums found.')
else:
print('Albums:')
for item in items:
print('{0} ({1})'.format(item['title'].encode('utf8'), item['id']))