Google Photos API - authentication

耗尽温柔 提交于 2019-12-06 16:25:32

问题


I'm trying to get list of my shared albums from Google Photos. I found a enable Photos API in Google Developers Console.

HTTP GET: https://content-photoslibrary.googleapis.com/v1/sharedAlbums?key=AIzaSyCkXXXXXXXXXXXXXZiOSe9IiyM8E

RESULT:

{ "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" } } 1

Configuration in developers console:

Please, what I'm doing wrong? Thank you.


回答1:


You need to configure OAUth 2.0 credentials (client ID and secret) and not an API key. More details are in the developer documentation here: https://developers.google.com/photos/library/guides/get-started#request-id

The Google Photos library API acts on behalf of a user, that's why you need to authenticate via OAuth 2.0. As part of this request you also need to specify a scope for your users to accept, see this page for more details: https://developers.google.com/photos/library/guides/authentication-authorization




回答2:


Google API need an access token to make sure that the user has the permission to access the feature. Access token is just like cookie that should be send together with the request.

Usually you will need so many setup to get the access token with your own code. But there are a client library that can help you access Google API with small setup.

Access token also has a lifetime, so if you don't use the library you will need to manually refresh the token.




回答3:


I've been working on a python project to backup google photos library and album info. you can probably modify it to do exactly what you want. It is fully working but does not currently distinguish between shared and private albums.

https://github.com/gilesknap/gphotos-sync

In particular, see https://github.com/gilesknap/gphotos-sync/blob/master/gphotos/authorize.py which handles authentication and authorization for any Google service (it also handles storing the token and refreshing the token).



来源:https://stackoverflow.com/questions/51943422/google-photos-api-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!