2013-02-11 40 views
1

我有社交媒體工具欄。和我有臉書按鈕,我的願望是當有人點擊Facebook像按鈕比找到用戶和存儲相關信息到我的數據庫促銷。如何在按按鈕之後獲取用戶信息

我已經做了這樣

window.fbAsyncInit = function() { 

     FB.Event.subscribe('edge.create', 
     function(response) { 
      var FBGraphURL = "http://graph.facebook.com/user/callback=?"; 

      FB.getLoginStatus(function(res) { alert(res); }); 

      FB.api('/me', function(resp) { 
       alert('Good to see you, ' + resp.username + '.'); 
      }); 
     }); 
    }; 

但還是resp.username顯示爲未定義。我該如何解決這個問題?

更新

工作代碼:

window.fbAsyncInit = function() { 
    FB.Event.subscribe('edge.create', function(response) { 
     login(); 
    }); 
}; 

function login() { 
    FB.login(function(response) { 
     if (response.authResponse) { 
      GetUser(); 
     } else { 
      // cancelled 
     } 
    }, {scope: 'email'}); 
} 

function GetUser() { 
    FB.api('/me', function(resp) { 
     alert('Good to see you, ' + resp.email + '.'); 
    }); 
} 

而且每個域都有不同的應用ID(重要

+1

你沒有得到有關用戶_any_信息,直到它們連接到您的應用程序。 – CBroe 2013-02-11 12:46:42

+0

yaa,true,但我已經登錄。還得不到 – 2013-02-11 12:49:19

回答

1

類似插件只返回你什麼網址像是被製造的。 要抓取用戶信息,您必須使用fb連接,並且當用戶接受您的應用程序時,您可以使用他的訪問令牌檢索他的信息!

在這裏尋找更多詳情:https://developers.facebook.com/docs/howtos/login/getting-started/

+0

非常感謝!你的幫助引導回答..謝謝 – 2013-02-12 09:05:38

相關問題