简体   繁体   中英

JavaScript Facebook graph API

TLDR :- JS amateur here. Call to Graph API, FB.INIT() did not work from my local machine. But worked from my Github static website. Why?

Detail : I am learning (or trying to learn) web app development on my own, after going thru some tutorials thought of creating webpage with JS which calls FB graph API.

Copied FB provided code to load SDK and logic to show like buttons.

Nothing happened when i opened HTML thru browser, but when I pushed it on GitHub it worked! Not sure why?

    <script>

  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'xxxxxxxxxxxxx',
      xfbml      : true,
      version    : 'v2.6'
    });
  };

  (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/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>
-----------------------------------------
**Code to show like/share buttons:-**

    <div
  class="fb-like"
  data-share="true"
  data-width="45"
  data-show-faces="true">
</div>

_____________________________________-

Thank you for taking time reading thru this.

It is because the url that you have specified for you Facebook app as callback url is that of github. You can change it for a while and test and see, it will work for "localhost" but not for "127.0.0.1".

Or you can create two apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM