我无法扩展列出专辑 ID 所需的 API 调用,以便能够列出专辑中包含的项目。下面是我为检索专辑 ID 所做的一个示例。除了那个例子之外,我还尝试扩展这个脚本,以便能够列出特定专辑中包含的项目。
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)
现在,对于我试图从上面的示例中修改的代码,以便能够列出由以下定义的给定专辑中的项目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()
当我尝试打印 时results
,我收到有关接收意外关键字参数的错误,albumId
.
api 调用的搜索格式不同,它是https://photoslibrary.googleapis.com/v1/mediaItems:search
错误是否源于 :mediaItems:search
使 Python 中的变量无效?还是与搜索调用是 POST 而不是 GET 的事实有关?或者是其他东西?