Search code examples
google-people-api

Google People API unauthorized


I want to get my own Google Contacts so I read up on the People API documentation, on the "Authorize Request" section under the "Acquiring and using an API key" it says:

API keys: A request that does not provide an OAuth 2.0 token must send an API key. The key identifies your project and provides API access, quota, and reports.

The API supports several types of restrictions on API keys. If the API key that you need doesn't already exist, then create an API key in the Console by clicking Create credentials > API key. You can restrict the key before using it in production by clicking Restrict key and selecting one of the Restrictions.

So that seems easy enough, I went to the project page and created an unrestricted API Key, then I can create this request URL: https://people.googleapis.com/v1/people/me?key=API_KEY&personFields=names, with the API key just in the URL, as this statement suggest.

After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs.

But when I run the URL I posted before it returns this:

{
    "error": {
        "code": 401,
        "message": "The request does not have valid authentication credentials.",
        "status": "UNAUTHENTICATED"
    }
}

What am I doing wrong? :(


Solution

  • Turns out the solution is pretty simple and I feel quite stupid, it isn't possible to access your own Google Contacts or any other private data using the API key, if you're trying to access any private data you should use OAuth 2.0 and not an API key (unlike for instance a public YouTube play-list where you CAN use an API key). Thanks to @Mateo Randwolf