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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With