在使用Facebook登录后,如何使用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>< /脚本>
然后我有这样的FB登录按钮代码:
< div id =fb-root>< / div>< script src =http://connect.facebook.net/en_US/all的.js#APPID = myAppId&放大器;放大器; XFBML = 1\" >
< / script>< fb:login-button show-faces =falseperms =user_hometown,user_about_me,email,user_address
autologoutlink =truewidth =200max-行= 1 >
< / fb:login-button>
然后在用户使用FB按钮登录后,如何进行JS调用以获取名字,电子邮件,照片等?
我还发现了一些这样的代码,但不知道这是用在哪里:
< script>
FB.init({
appId:'myAppId',
status:true,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true,//解析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 =falseperms =user_hometown,user_about_me,email,user_addressautologoutlink =truewidth =200max-rows =1 >< / FB:登录按钮>
<! - 把它放在结束体标签之前 - >
< script src =http://connect.facebook.net/en_US/all.js>< / script>
< script>
FB.init({
appId:'myAppId',
status:true,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true,//解析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);
});
如果一切顺利,响应
应该是包含您有权查看的用户数据的JSON对象。
用户图像可以从:
http://graph.facebook.com/FACEBOOK_USER_ID/picture
您可以使用类型参数指定所需的大小
- square - 50x50
- small - 50像素宽,可变高度
- 正常 - 100像素宽,可变高度
- 大 - 大约200像素宽,可变高度
例如:
http://图.facebook.com / FACEBOOK_USER_ID / picture?type = large
I have this in my header:
<script src="http://connect.facebook.net/en_US/all.js"></script>
Then I have the FB login button code like this:
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=myAppId&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>
Then after the user logs in with the FB button, how do I make a JS call to get their name, email, photo, etc?
I also found some code like this, but not sure where this is used:
<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>
Do I need the code right above?
Thanks!!
<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>
To get logged users data:
FB.api('/me', function(response) {
console.log(response);
});
If all went well response
should be a JSON object containing the user data you have permission to view.
The users image can be gotten from:
http://graph.facebook.com/FACEBOOK_USER_ID/picture
You can specify the size you want with the type argument
- square - 50x50
- small - 50 pixels wide, variable height
- normal - 100 pixels wide, variable height
- large - about 200 pixels wide, variable height
For example:
http://graph.facebook.com/FACEBOOK_USER_ID/picture?type=large
这篇关于在使用Facebook登录后,如何使用JS SDK获取用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!