FB-Connect简单脚本不能正常工作

问题描述:

<html xmlns="http://www.w3.og/1999/xhtml" xmlns:fb="http://facebook/2008/fbml"> 
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script> 


<fb:login-button onlogin="update_user_box();"></fb:login-button> 

<script> 
function update_user_box(){ 
user_box = document.getElementById("user"); 
user_box.InnerHtml = "<span>" 
+"<fb:profile-pic uid='loggedinuser' facebook-logo=true></fb:profile-pic>" 
FB.XFBML.Host.parseDomTree(); 
} 
FB.init("APP_ID","xd_reciever.htm"); 

</script> 
<div id="user"></div> 

这是我的脚本。其实我想从Facebook连接取得登录用户的个人资料图片。但这是行不通的,我从http://mashable.com/2008/12/11/facebook-connect-blog/得到这个脚本,我找不到我的错误。如何让它正确工作,就像我想要的一样?FB-Connect简单脚本不能正常工作

+0

该脚本只是过时了 - 不应再使用'FeatureLoader.js.php'脚本。请阅读有关如何嵌入和使用_current_ JS SDK的文档:https://developers.facebook.com/docs/reference/javascript/ – CBroe 2012-07-30 09:44:54

这应该为你工作...

// assume we are already logged in 
    FB.init({appId: 'YOUR_APP_ID', xfbml: true, cookie: true}); 

    function showProfile(response) { 

if (response.authResponse) { 
     //user is already logged in and connected 
     var userInfo = document.getElementById('user'); 
     FB.api('/me', function(response) { 
     userInfo.innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name; 
     }); 
    } 
    } 

    // run once with current status and whenever the status changes 
    FB.getLoginStatus(showProfile); 
    FB.Event.subscribe('auth.statusChange', showProfile); 


    (function() { 
      var e = document.createElement('script'); e.async = true; 
      e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
      document.getElementById('fb-root').appendChild(e); 
    }()); 

然后有两个div的登录按钮以及用于存储个人资料信息。

<div class="fb-login-button" autologoutlink="true"></div> 
<div id="user"></div>