0
votes

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? :(

1
Have you enabled People API in your Google Workspace project ? Could you show us the request you are making without providing any sensitive data? Which method of People API are you using? What scopes are you using? Thanks ! :DMateo Randwolf
@MateoRandwolf I have enabled the People API, in the question I tried to use the "Read Profiles" request as you can see in the example URL, I didn't set any scopes as I didn't see that in the "Authorization" section. "List the user's contacts" requests also don't seem to work with the API key, as I get this in return "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."Schotsl
So are you running this in a Javascript application or with which language are you intending to do these API calls? Did you just run that URL? Is the data you are trying to access public or is it private? If the data is private you will need to authorise using OAuth 2.0.Mateo Randwolf
Ahhh, I'm feeling pretty stupd right about now. I had assumed that since I own the project with the API key it would be able to view MY contacts but I guess it doesn't work that way, I wanted to avoid using OAuth since an API key is simpeler to implement but I guess I will have to. Thanks for the help though!Schotsl

1 Answers

0
votes

Turns out the solution is pretty simple and I feel quit 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