繁体   English   中英

如何使用JS SDK登录后获取用户信息

[英]How to get User info using JS SDK after they login with Facebook

我的标题中有这个:

<script src="http://connect.facebook.net/en_US/all.js"></script>

然后我有这样的FB登录按钮代码:

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=myAppId&amp;xfbml=1">
</script><fb:login-button show-faces="false" perms="user_hometown,user_about_me,email,user_address"
autologoutlink="true" width="200" max-rows="1">
</fb:login-button>

然后在用户使用FB按钮登录后,如何进行JS调用以获取他们的姓名,电子邮件,照片等?

我也发现了一些像这样的代码,但不知道在哪里使用它:

<script>
  FB.init({
    appId  : 'myAppId',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    channelURL : 'http://www.comehike.com/channel.html', // channel.html file
    oauth  : true // enable OAuth 2.0
  });
</script>

我需要上面的代码吗?

谢谢!!

<html>
<head> ... </head>
<body>
    <div id="fb-root"></div>

    <fb:login-button show-faces="false" perms="user_hometown,user_about_me,email,user_address" autologoutlink="true" width="200" max-rows="1"></fb:login-button>


    <!-- put this before the end body tag -->
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
      FB.init({
        appId  : 'myAppId',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true, // parse XFBML
        channelURL : 'http://www.comehike.com/channel.html', // channel.html file
        oauth  : true // enable OAuth 2.0
      });
    </script>
</body>
</html>

要获取记录的用户数据:

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

如果一切顺利,则response应该是包含您有权查看的用户数据的JSON对象。

用户图像可以从以下位置获得:

http://graph.facebook.com/FACEBOOK_USER_ID/picture

您可以使用type参数指定所需的大小

  • 方块 - 50x50
  • 小 - 50像素宽,可变高度
  • 正常 - 100像素宽,可变高度
  • 大 - 宽约200像素,高度可变

例如:

http://graph.facebook.com/FACEBOOK_USER_ID/picture?type=large

暂无
暂无

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

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