首页 > 解决方案 > 谷歌照片 API 和获取单张照片

问题描述

我尝试从选定的专辑中获取照片,这就是为什么我只想在给定的专辑 ID 中列出 mediaItems。然而,这并没有改变,只是返回 400 http 代码。albumId 是正确的,因为我首先通过 API 检查它,它也给了我

from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools


ALBUM_ID = "???"
# Setup the Photo v1 API
SCOPES = [
    'https://www.googleapis.com/auth/photoslibrary.readonly',
    'https://www.googleapis.com/auth/photoslibrary.sharing'
    ]
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().get(albumId=ALBUM_ID,).execute()
print(results)
#json = '{"albumId":"%s","pageSize":100}' % ALBUM_ID
zison = '{"albumId":"%s"}' % ALBUM_ID
mediaItems = service.mediaItems().search(body=zison).execute()
print(mediaItems)
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']))

列出此资源的正确方法应该是什么?

标签: pythongoogle-photos

解决方案


推荐阅读