user1040091
user1040091

Reputation: 21

FB.Event.subscribe does not work

I am very new to Facebook.

I have a very simple question. How to make FB.Event.subscribe work?

My test is only having a like box and I'd like an alert window when the user clicks the like box.

Below is my code:

<!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>

The like box shows, but no alert shows when I click it.

Upvotes: 1

Views: 5521

Answers (3)

user603007
user603007

Reputation: 11794

no the like button works at least in Chrome, try this(does not work in 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> 

Upvotes: 1

Eric
Eric

Reputation: 1

The bug you referenced is for the the like button not the like-box. I have been unable to get the edge.create callback to work for the fb:like-box but it works fine for the fb:like. Wish it would work on both.

Upvotes: 0

Vincent Edwards
Vincent Edwards

Reputation: 11

This is a facebook bug, I reported it here:

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

Upvotes: 1

Related Questions