I try to access Google user info trough API request;
https://www.googleapis.com/oauth2/v1/userinfo?access_token=ya29.a0Ael9sCMYNzgxZT27Cb....
All I am getting for response is Id and profile pic:
{
"id": "1.....",
"picture": "https://lh3.googleusercontent.com/a-/ACB-R5Sg...."
}
I need more user info: email, name, etc.
I have added user.profile and userinfo.email and userinfo.profile scopes in developer console.
I know added scopes can take 5mins-few hours to work but I added it ~12h ago.
How to fix my API REST call to get more user info from Google API?
EDIT
This question is same, but the answer didnt work for me. This request:
https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses&access_token=ya29.a0...&key=498...apps.googleusercontent.com
Got me Request had insufficient authentication scopes
error.
Maybe I am providing wrong key there? What should be api key then, its client id from credentials page?
I have found my mistake. I wasnt providing a scope in the primary request. So actions to receive google acccount info goes like this:
GET request:
https://accounts.google.com/o/oauth2/v2/auth?
scope=https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email
&redirect_uri=https://www.youtube.com/
&response_type=code
&client_id=498...apps.googleusercontent.com
This code opened me a desired page (youtube in this case) after registration with code:
https://www.youtube.com/?
code=4%....
&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+openid
&prompt=consent
I copied given code to POST request:
https://oauth2.googleapis.com/token?
code=4%2...
&client_id=498....apps.googleusercontent.com
&client_secret=GO...
&redirect_uri=https://www.youtube.com/
&grant_type=authorization_code
And got:
{
"access_token": "ya29....",
"expires_in": 3599,
"scope": "openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
"token_type": "Bearer",
"id_token": "eyJhb...."
}
Now with final request
https://www.googleapis.com/oauth2/v3/userinfo?access_token=ya29...
I receive more info:
{
"sub": "10....",
"name": "V....",
"given_name": "V....",
"family_name": "L....",
"picture": "https....",
"email": "vy...",
"email_verified": true,
"locale": "lt"
}