javascript - FB.Event.subscribe code not working - Stack Overflow

I am using this code to get the response:<fb:like layout="button_count" notify="true&

I am using this code to get the response:

<fb:like layout="button_count" notify="true" colorscheme="dark" href=""></fb:like>
<script>
  // this will fire when any of the like widgets are "liked" by the user
  FB.Event.subscribe('edge.create', function(href, widget) {
    alert('You liked ' + href, widget);
  });
</script>

It's not giving any response. Can anyone tell what wrong am i doing ?

I am using this code to get the response:

<fb:like layout="button_count" notify="true" colorscheme="dark" href="http://www.fbrell."></fb:like>
<script>
  // this will fire when any of the like widgets are "liked" by the user
  FB.Event.subscribe('edge.create', function(href, widget) {
    alert('You liked ' + href, widget);
  });
</script>

It's not giving any response. Can anyone tell what wrong am i doing ?

Share Improve this question asked Jan 7, 2012 at 19:38 Pankaj SharmaPankaj Sharma 6796 silver badges12 bronze badges 1
  • Your sample is just working correctly. Do you have any errors on page before? Does number of likes increases once you pressing the "Like Button"? – Juicy Scripter Commented Jan 7, 2012 at 19:56
Add a ment  | 

3 Answers 3

Reset to default 1

Assuming that you have the FB Like button appearing, so you must be including the SDK correctly, I was in exactly the same situation - all you're missing is setting the subscribe up in the fbAsyncInit() function.

window.fbAsyncInit = function () {
    FB.Event.subscribe('edge.create', function (targetUrl) {
        _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
    });
};

If you're doing this you don't need an application ID nor do you you need to use the FBML code, you can use the HTML5 inclusion code like <div class='fb-like' data-href='...

  1. You're missing the inclusion of the javascript SDK files.
  2. You're missing the FB.init
  3. You're not running your code within the fbAsyncInit() function.

See https://developers.facebook./docs/reference/javascript/ for more information.

Checklist:

(Im assuming you have setup the Javascript SDK)

run the FB linter on your url, errors here may stop it working

http://developers.facebook./tools/debug

Include this at the top of the page

<html xmlns="http://www.w3/1999/xhtml" xmlns:fb="http://www.facebook./2008/fbml">

If your liking an app, include on your app page

<meta property="fb:app_id" content="Your app id" />

Like button, change href to your link

<fb:like layout="button_count"  show_faces="false" height="21" href="http://facebook."></fb:like>

If its an app, FB prefers HTTPS

function init() {
       FB.init({
            appId: APP_ID,
            status: true,
            cookie: true,
            xfbml: true,
            oauth: true
        });

    //unment if required 
    //window.fbAsyncInit = function() { 
    FB.Event.subscribe('edge.create',
        function(response) {
            alert('You liked the URL: ' + response);
        }
    );
   //}
}
init();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745492366a4630041.html

相关推荐

  • javascript - FB.Event.subscribe code not working - Stack Overflow

    I am using this code to get the response:<fb:like layout="button_count" notify="true&

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信