Facebook JS API: users_getInfo() inside ifUserConnected() deadlock
I am trying to put Facebook connect button on the site and once connected display connected username. But for some reason following code goes into some infinite loop during first connection, and then works fine unless I delete this app from my facebook profile which causes freezing again.
Here is a code on FB connect button click:
FB.Connect.requireSession();
Here is code directly on the page:
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>
<script type="text/jav开发者_StackOverflow中文版ascript">
FB.init("123", "/xd_receiver.htm");
FB.ensureInit(function() {
FB.Connect.ifUserConnected(function() {
FB.Facebook.apiClient.users_getInfo(new Array(FB.Connect.get_loggedInUser()),new Array("name"), function(user, exec) {
console.log("logged in:"+user[0].name);
});
}, function(){
console.log("guest");
});
});
</script>
If I remove FB.Facebook.apiClient.users_getInfo()
it works fine, but I need to get username somehow. Any tips?
Thanks.
You can get like this;
FB.Facebook.apiClient.users_getInfo(loggedInUsersId, ['first_name','last_name','email','sex','birthday','username'], function(result,ex){
alert(result[0]['username']);
});
For that you need to pass username parameter as array like:
FB.Facebook.apiClient.users_getInfo(new Array(FB.Connect.get_loggedInUser()),new Array("name","username"), function(user, exec) {
console.log("logged in:"+user[0].name);
});
精彩评论