1

我有一个 Facebook 页面。我想知道一个人是否点击了like按钮并在subscribe.event 'create-edge'回调中做某事。如果一个人已经登录 Facebook,这可以正常工作。事件'create-edge'被触发。但是,如果一个人未登录,则不会触发此事件。

我没有appId,所以我什么都不发送。

供您参考的代码:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#" >
<head>
<meta charset="utf-8">
<title>Facebook Like Button</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
  appId      : '', // App ID
  channelURL : '', // Channel File
  status     : true, // check login status
  cookie     : true, // enable cookies to allow the server to access the session
  oauth      : false, // enable OAuth 2.0
  xfbml      : true  // parse XFBML
});
FB.Event.subscribe('edge.create', function(response) {
    alert("say something");
    //my code
});
FB.Event.subscribe('auth.login', function(response) {
    alert('The status of the session is: ' + response.status);
});   
};

// Load the SDK Asynchronously
(function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<fb:like href="http://www.facebook.com/My_Page" send="false" layout="button_count"     width="450" show_faces="false"></fb:like>
</body>
</html>

而且我也收到了这个错误:

在调用 FB.init() 之前调用 FB.getLoginStatus()。

好像我收到了,因为我没有appId要寄的东西FB.init。这是什么原因?

4

1 回答 1

0

如果用户已经喜欢您的页面并且未登录,则会发生这种情况。要解决此问题,我必须将 FB.init() 放入循环中.. 像这样:

setInterval(function()
        {
            FB.init({
                appId      : 'app_id'
                channelUrl : 'channel_url'
                status     : true, // check login status
                cookie     : true, // enable cookies to allow the server to access the session
                xfbml      : false  // parse XFBML
            });

        }, 5000);
于 2013-10-03T18:30:32.767 回答