Facebook javascript API: get username and image by session?

If I can get the response.session object, can I use it to get the current username and profile of the profile?

thank

+3
source share
6 answers
FB.api('/me', function(response) {
    alert("Name: "+ response.name + "\nFirst name: "+ response.first_name + "ID: "+response.id);
    var img_link = "http://graph.facebook.com/"+response.id+"/picture"
});

More details here:

http://developers.facebook.com/docs/reference/javascript/FB.api/

+13
source

In addition, you can get more personalized information about the connected user:

FB.api('/me', function(response) {
                console.log(response);
                });

Hope that helps

+3
source

:

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // the user is logged in and connected to your
    // app, and response.authResponse supplies
    // the user’s ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    //but not connected to the app
  } else {
    // the user isn't even logged in to Facebook.
  }
});

: https://developers.facebook.com/blog/post/525/

+1
FB.getLoginStatus(function(response) {
    if (response.session) {
//response.session contains what you lokks for
} else {
// user is not connected..
}
0

, .

0

After that you managed to get the object of the response session, you can do the following

            var rec="Name : "+response.name+"";
            rec +="Link: "+response.link+"";
            rec +="Username: "+response.username+"";
            rec +="id: "+response.id+"";
            rec +="Email: "+response.email+"";

            function getPhoto()
            {
            FB.api('/me/picture?type=normal', function(response) {
            var img=response.data.url;
            });

For more information, you can refer to this guide: https://developers.facebook.com/docs/javascript/reference/FB.api

0
source

All Articles