当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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/javascript">

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);
            });
分享给朋友:
您可能感兴趣的文章:
随机阅读: