LIke button of facebook will not fire edge.create or edge.remove in web page

瘦欲@ 提交于 2019-12-10 10:55:36

问题


I have prefered given answer of stackoverflow question

Like button will not fire edge.create or edge.remove .

But I am getting following error when see in developer tool console in crome browser

"Uncaught ReferenceError: FB is not defined fb.php:20

Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

code is as follow

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<html xmlns:fb="http://ogp.me/ns/fb#">
 <body>
 <div id="fb-root"></div>
 <script>(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&appId=xxxxx";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

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

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

</script>
<div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>

 </body>
</html>

How can resolve it please help me.

Thanking you.


回答1:


You have not initialized the FB.init(), without which you can not make API calls-

window.fbAsyncInit = function() {
    FB.init({
      appId      : '510509449056378',
      status     : true,
      xfbml      : true
    });
    FB.Event.subscribe('edge.create',
       function(response) {
         alert('You liked the URL: ' + response);
       }
    );

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

(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&appId=510509449056378";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));



回答2:


<!DOCTYPE html>
<head>
<title>
Like Box example
</title>
</head>
<body>
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
            FB.init({
                    appId: '{APP_ID}'
            });
            FB.Event.subscribe('edge.create', function(response) {
                    alert('You liked the URL: ' + response);
            });
            FB.Event.subscribe('edge.remove',function(response) {
                   alert('You UNliked the URL: ' + response);
            });
    };

        (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id; //js.async = true;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId={APP_ID}";
            fjs.parentNode.insertBefore(js, fjs);
         }(document, 'script', 'facebook-jssdk'));
</script>

<!--Like BOX-->
<fb:like-box href="https://developers.facebook.com/docs/plugins/" colorscheme="light" show_faces="false" header="false" stream="false" show_border="false"></fb:like-box>

</body>
</html>


来源:https://stackoverflow.com/questions/23005569/like-button-of-facebook-will-not-fire-edge-create-or-edge-remove-in-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!