如何使用開放圖API顯示Facebook登錄按鈕並在成功登錄後獲取用戶名和電子郵件?我試過這個,但沒有成功。登錄時使用Facebook Open Graph API時出錯
我這頭部分:
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
FB.init({
appId: '12345', cookie: true,
status: true, xfbml: true
});
FB.api('/me', function (user) {
if (user != null) {
alert(user.name);
}
});
</script>
我只是</body>
標記之前<div id="fb-root"></div>
在最後。到現在爲止還挺好。我的<fb:comments> and <fb:comments-count>
可以在我網站上的任何頁面上正常工作。但我不能讓我的登錄工作(它說我沒有做FB-根定義)
我有這樣的地方在我的頁面的中間:
<fb:login-button perms="email,user_checkins">Login with Facebook</fb:login-button>
提交在登錄後窗口,我得到一個js錯誤,說fb-root div沒有定義。但是我確實已經在頁面的最後。
如果可以的話,請使用php方案..好得多... – Shouvik 2011-03-26 09:50:42
也許不相關,但不要在沒有確定您之前登錄的情況下使用/我。查看我的答案以獲得更好的選擇。 – Aleadam 2011-03-30 23:52:16