2012-07-29 53 views
0
<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

回答

0

這應該爲你工作...

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