[英]how to get info of user when they login via Facebook using javascript
[英]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&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參數指定所需的大小
例如:
http://graph.facebook.com/FACEBOOK_USER_ID/picture?type=large
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.