Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get user profile using Google Access Token

Tags:

i'm testing getting user information by google access token

http://www.mawk3y.net/glogin

after clicking sign in button i get redirected to

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=access_token_here

And get some JSON data like this

{ "issued_to": "my client id.apps.googleusercontent.com", "audience": "my client id.apps.googleusercontent.com", "user_id": "user id here", "scope": "https://www.googleapis.com/auth/plus.login", "expires_in": 3596, "access_type": "online" } 

now i need to know how to extract user name , address and email any help please ?

thanks in advance

like image 656
jq beginner Avatar asked May 11 '13 21:05

jq beginner


People also ask

Does access token have user info?

Sample access tokenThe token does not contain any information about the user except for the user ID (located in the sub claim). In many cases, you may find it useful to retrieve additional user information. You can do this by calling the userinfo API endpoint with the Access Token.

How do I use my Google ID token?

To sign in or sign up a user with an ID token, send the token to your app's backend. On the backend, verify the token using either a Google API client library or a general-purpose JWT library. If the user hasn't signed in to your app with this Google Account before, create a new account.

What data can I get from Google login?

After you have signed in a user with Google using the default scopes, you can access the user's Google ID, name, profile URL, and email address.


1 Answers

Try this one:

 var url = 'https://www.googleapis.com/plus/v1/people/me?access_token={access_token}';    $.ajax({     type: 'GET',     url: url,     async: false,     success: function(userInfo) {       //info about user       console.log(userInfo);       console.log('test');     },     error: function(e) {       console.log('error');      }   }); 
like image 56
betmakh Avatar answered Oct 06 '22 02:10

betmakh