繁体   English   中英

Facebook javascript API:按会话获取用户名和图片?

[英]Facebook javascript API: get username and image by session?

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

谢谢

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

更多信息:

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

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

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

希望有所帮助

以下是三种可能的状态:

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/

之后,您设法获得响应会话对象,您可以执行以下操作

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

有关详细信息,请参阅本手册: https//developers.facebook.com/docs/javascript/reference/FB.api

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM