Facebook javascript API:通过会话获取用户名和图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5394224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:59:52  来源:igfitidea点击:

Facebook javascript API: get username and image by session?

javascriptfacebook

提问by Johan

If i manage to get a response.session object, can i use it to get the current logged in users username and profile image?

如果我设法得到一个 response.session 对象,我可以用它来获取当前登录用户的用户名和个人资料图片吗?

Thanks

谢谢

回答by Aleadam

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 info here:

更多信息在这里:

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

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

回答by nka11

Additionnaly, you can get more personnal informations about connecteduser :

此外,您可以获得有关已连接用户的更多个人信息:

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

Hope that helps

希望有帮助

回答by Tamas Kalman

Here are the three possible states:

以下是三种可能的状态:

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

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

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

回答by Alex

After, you managed to get response session object, you can do 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 info you can refer to this manual: https://developers.facebook.com/docs/javascript/reference/FB.api

有关更多信息,您可以参考本手册:https: //developers.facebook.com/docs/javascript/reference/FB.api

回答by nka11

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

回答by Rhea

If the user is logged in and has authorized your application, you should be able to.

如果用户已登录并已授权您的应用程序,您应该可以。