3

I am developing a Google Chrome Extension. I would like to be able to access the user profile info, using the data from these endpoints:

https://www.googleapis.com/auth/userinfo

https://www.googleapis.com/oauth2/v1/userinfo

I don't seem to have access to these resources. From my web searches, it looks like I may need to enable a library API in the Google Developers Console. But I looked there and cannot find an appropriate API to enable. Does anyone know which API I should enable?

4
  • In the case of use of https://www.googleapis.com/oauth2/v1/userinfo, it is not required to enable API related to this. You can use the endpoint by access token retrieved from OAuth2 process. When you use this, please include https://www.googleapis.com/auth/userinfo.profile to the scopes. If this information was not useful for you, I'm sorry. Commented Feb 5, 2018 at 23:16
  • This is an additional information. As a test, I used it without enabling all APIs. The sample curl command is curl -H "Authorization: Bearer ### access token ###" "https://www.googleapis.com/oauth2/v1/userinfo". I confirmed that it worked. The scope of token is only https://www.googleapis.com/auth/userinfo.profile. About the endpoint, https://www.googleapis.com/oauth2/v1/userinfo and https://www.googleapis.com/oauth2/v2/userinfo return the same information. Commented Feb 5, 2018 at 23:32
  • do you know what the difference is between the two urls in the OP? Commented Feb 5, 2018 at 23:41
  • About userinfo, it returns the same information. Also v3 is the same. It seems that about the endpoints except for userinfo, there is the difference between versions. stackoverflow.com/questions/31277898/… Commented Feb 5, 2018 at 23:54

3 Answers 3

5

You will need to at least add the scope https://www.googleapis.com/auth/userinfo.profile as per mentioned.

Then you can use the oauth2 apis just like how would you use sheets, calendar etc.

In nodejs, it'd be something like this:

    const { google } = require('googleapis')
    const auth = new google.auth.OAuth2(
      keys.web.client_id,
      keys.web.client_secret,
      keys.web.redirect_uris[0]
    )
    // get the tokens from google
    auth.credentials = tokens
    const oauth2 = google.oauth2({ version: 'v2', auth })
    const userinfo = await oauth2.userinfo.get()
    console.log(userinfo)

The api is documented here: https://googleapis.dev/nodejs/googleapis/latest/oauth2/interfaces/Schema$Userinfo.html#info. There are also some examples in the source code there.

Sign up to request clarification or add additional context in comments.

Comments

2

If you need just user's email-address for auth etc., you have to enable Google's Plus API, not the G**-*****d People API which is mentioned everywhere in the Google Cloud API docs.

Also, you need to mention the scope https://www.googleapis.com/auth/userinfo.email, not the https://www.googleapis.com/auth/userinfo.profile one.

p.s. It's an old question, yet unanswered. Possibly, you've already solved it. I'm posting it for people from the future, or just for my future self.

2 Comments

You should know that Google+ related APIs are being shut down in January '19. More at Google blog.
if google+ is become shutdown... wouldn't safe if we use gmail api?
2

You can retrieve data from these endpoints if you have an access token from the user. First, you have to get an access token by letting the user login using google login API. Then retrieve the data from the following link. https://www.googleapis.com/oauth2/v1/userinfo?access_token=PUT_YOUR_USER'S_ACCESS_TOKEN_HERE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.