我有一些python代码可以成功验证并从google photos api中提取各种对象。
from googleapiclient.discovery import build
def build_service(credentials):
API_SERVICE_NAME = 'photoslibrary'
API_VERSION = 'v1'
return build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
def get_albums(service):
results = service.albums().list().execute()
return results.get('albums', [])
def get_pictures(service,album_id: str):
body = {
"albumId": album_id,
"page_size": 10
}
print(body)
results = service.mediaItems().search(body=body).execute()
return results
def get_picture_url(service,media_item_id: str):
return service.mediaItems().get(mediaItemId=media_item_id)
除get_picture_url之外的所有功能均起作用,这导致以下响应。通过外壳工作,我可以使用list方法成功列出mediaItems,但无法通过get()方法访问它们。
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
编辑:我的范围设置为只读。