2

Trying to build an Angular 6 application to display all photos from a particular Google Photos album. Before implementing the Angular portion, I wanted to see if I could get the data from a cURL command, using the API key I created and gave access to the Photos API.

cURL:

 curl -X GET \
  'https://photoslibrary.googleapis.com/v1/mediaItems?pageSize=1&key=[API KEY]' \
  -H 'Accept: application/json' \

This is based on the samples from Google's documentation here: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/list

However, adding my valid API key results in the following error:

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

Is there additional data required besides the API key to get this working? Is it even possible to use an API key in this manner, or does it require using OAuth 2.0 and all the additional hoops that come with it?

4

1 回答 1

1

您需要获取 OAuth AccessToken 以作为 HTTP 标头添加到您的请求中。 这是我使用的有效流程的细分,但需要注意的是它会定期从 mediaItems 请求中获取 401 错误。谷歌似乎正在限制这些请求,如果它们来得太快,就会拒绝一些请求。

于 2018-12-20T19:51:16.443 回答