Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get google account information after login in my website with google sign in (Used satellizer lib for login)

I have used satellizer and node server for login in my website with google sing in.

I have successfully login and following data added in mongodb database.

{
    "_id" : ObjectId("57adec45a8fb51401c1ba843"),
    "displayName" : "xyz user",
    "picture" : "https://lh3.googleusercontent.com/-xxxxxxx_xx/xxxxxx/xxxxxxx/xxxxxxx/photo.jpg?sz=200",
    "google" : "100379763204xxxxxxxxx", //user id
    "__v" : 0
} 

Now, I want to get other information from google account like Gender, Phone Number, Location etc...

So, How to get all information of login user from google account?

like image 629
Mehul Mali Avatar asked Oct 30 '22 22:10

Mehul Mali


2 Answers

Not all of that information is actually available. It will also depend upon if the user has set the information to public or not.

If you use the People: get method it will return a person resource Resource. Assuming the user has this information public you should see the information you are after. This method is part of the Google+ api so it will only work if the user has a Google+ account.

There is also the People API which tends to return similar information people.get. I am not sure exactly were this information is coming from. It appears to be related to a users Google account as opposed to the Google+ account.

like image 158
DaImTo Avatar answered Nov 11 '22 03:11

DaImTo


I finally success , there is my solution :

getGoogleDatas: function (id) {
    return $http.get("https://www.googleapis.com/oauth2/v1/userinfo", {
        params: {
            access_token: $auth.getToken(),
            alt: 'json'
        }
    });
}

and then :

getGoogleDatas().then(function (response) {
    user = response;
}).catch(function (error) {
    console.log('error:', error);
});
like image 26
Dan M. CISSOKHO Avatar answered Nov 11 '22 04:11

Dan M. CISSOKHO