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
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.
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.
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.
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'); } });
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