Facebook API FB.getLoginStatus返回未定义
我在我的网站上添加了一个类似按钮,并且想知道是谁点击了类似按钮。 这些是我的示例代码:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '182722795115444', status: true, cookie: true,
xfbml: true});
// To find who clicked the like button
FB.Event.subscribe('edge.create', function(response){
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
alert("logged in and connected user");
} else {
// no user session available, someone you dont know
alert("no user session available");
}
});
});
};
(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);
}());
</script>
<script src="http://connect.facebook.net/en_US/all.js#appId=182722795115444&xfbml=1"></script>
<fb:like href="www.blogcountry.net" send="true" width="450" show_faces="true" font=""></fb:like>
当我点击Like按钮和登录Facebook时,如同成功一样,但得到“无用户会话可用”警报。
所以我很困惑:
提前致谢。
更新:
@OffBySome谢谢你的回答。
你的意思是我必须调用FB身份验证API,然后我才能获取用户的信息? 但是...在Facebook开发文档FAQ:
如何知道用户何时点击Like按钮?
如果您使用按钮的XFBML版本,则可以通过FB.Event.subscribe订阅“edge.create”事件。
所以,这意味着我不知道谁点击了Like按钮,只知道点击了按钮。
如果我想获取用户的信息,我必须在单击Like之前实施登录操作? 这是非常糟糕的可用性。
任何人都可以给出一个好主意来解决它...
我很确定你不会仅仅喜欢一个页面就能获得Facebook会话。 通常,只有通过应用程序进行身份验证(例如,使用<fb:login-button autologoutlink="true"></fb:login-button>
)才能获得用户的Facebook会话。 如果做一个alert(JSON.stringify(response));
在那个函数里面你会得到什么值?
尝试这个..
FB.Event.subscribe('edge.create', function(href, widget)
{
alert('You just liked '+href);
session = FB.getSession();
uid = session['uid'];
alert(uid);
});
今天有同样的问题,这个线程解决了我 - FB.getLoginStatus里边edge.create回调从弹出窗口登录后返回未知状态和空会话
FB.getLoginStatus方法的第二个参数必须设置为'true'
链接地址: http://www.djcxy.com/p/6081.html