Darendal
Darendal

Reputation: 863

401 Unauthorized on Google Photos API with API Key

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?

Upvotes: 2

Views: 1932

Answers (1)

Rich Moss
Rich Moss

Reputation: 2384

You need to obtain an OAuth AccessToken to add as an HTTP Header in your request. Here's a breakdown of the process I've used that has worked, with the caveat that it periodically gets 401 errors from the mediaItems requests. It seems that Google is throttling the requests and denies a few if they're coming too fast.

Upvotes: 1

Related Questions