FB.Event.subscribe不起作用

时间:2011-11-10 16:05:25

标签: javascript facebook-javascript-sdk

我对Facebook很新。

我有一个非常简单的问题。如何让FB.Event.subscribe工作?

我的测试只有一个之类的框,当用户点击之类的框时,我想要一个提醒窗口。

以下是我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head>
    <title>My Test</title>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '122001581243857', // App ID
      channelURL : 'http://www.tagbeta.ca/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });
  };

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

//Code about the Like Box
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

//Code to response the click of the Like Box
FB.Event.subscribe('edge.create',
    function() {
        alert('Like box is clicked');
    }
);

</script>

<div>
    <fb:like-box href="http://www.facebook.com/platform" width="292" height="500" show_faces="true" border_color="red" stream="true" header="true"></fb:like-box>
</div>
</body>
</html>

like 框显示,但点击它时没有显示警告。

3 个答案:

答案 0 :(得分:1)

这是一个facebook错误,我在这里报道:

https://developers.facebook.com/bugs/212306515506386

答案 1 :(得分:1)

至少在Chrome中没有相似的按钮,请尝试此操作(在IE 9中不起作用):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="fb.aspx.cs" Inherits="stackoverFlowFb.fb" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#"> 
<head id="Head1" runat="server"> 
    <title></title> 
</head> 
<body> 
    <div id="Div1"> 
    </div> 
    <script type="text/javascript"> 
        (function (d, s, id) { 
            var js, fjs = d.getElementsByTagName(s)[0]; 
            if (d.getElementById(id)) { return; } 
            js = d.createElement(s); js.id = id; 
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; 
            fjs.parentNode.insertBefore(js, fjs); 
        } (document, 'script', 'facebook-jssdk'));</script> 
    <form id="form1" runat="server"> 
    <div> 
        <div id="fb-root"> 
        </div> 
        <fb:like href="http://news.drive.com.au/photogallery/drive/mazda-takeri-20111025-1mhtk.html" send="false" width="450" show_faces="false"> 
        </fb:like> 
        <script src="http://connect.facebook.net/en_US/all.js"></script> 
        <script> 
            FB.init({ 
                status: true, // check login status 
                cookie: true, // enable cookies to allow the server to access the session 
                xfbml: true  // parse XFBML 
            }); 
        </script> 
        <script type="text/javascript"> 

            FB.Event.subscribe('edge.create', 
    function (response) { 
        alert('You liked the URL: ' + response); 
    }); 

        </script> 
    </div> 
    </form> 
</body> 
</html> 

答案 2 :(得分:0)

您引用的错误是类似按钮而不是类似框。我无法让edge.create回调适用于fb:like-box,但它适用于fb:like。希望它能同时发挥作用。