Do I need an appId for a XFBML version of the Facebook Like button?

后端 未结 3 2006
有刺的猬
有刺的猬 2020-12-02 01:52

I\'m really confused.

I\'m trying to use some of the very simple Facebook plugins on my site, specifically the basic \"Like\" button.

I already know how to u

相关标签:
3条回答
  • 2020-12-02 02:27

    Answering my own question, after pulling out all my hair...

    http://developers.facebook.com/docs/guides/web/

    "The JavaScript SDK requires that you register your website with Facebook to get an App ID (or appId). The appId is a unique identifier for your site that ensures that we have the right level of security in place between the user and your website. The following example shows how to load the JavaScript SDK once you have your appId:"

    http://developers.facebook.com/setup/

    The title of that page/form is Create an App. I still don't understand why they don't use more generic terminology. I'm not "creating an app" and I don't consider my website to be an app.

    0 讨论(0)
  • 2020-12-02 02:35

    you can do...

    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#" >
    
    ...
    
    window.fbAsyncInit = function() {  
    FB.init({
      // appId      : 'none', // App ID
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    
    FB.Event.subscribe('edge.create', function(href, widget) {  
                var ss=href;
                if (ss.match(/myWebSite/i)) {
                        alert('You just liked me');
                }
    });
    };  
    
    (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 = "https://connect.facebook.net/en_GB/all.js#xfbml=1";
      //js.src = "https://connect.facebook.net/en_GB/all.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    
    ...
    
    <fb:like ref="core" class="fb-like" data-href="http://www.mySite.com" 
    data-send="false" data-layout="button_count" 
    data-width="50" data-show-faces="false" data-colorscheme="dark"></fb:like>
    

    the above works, but Like yourself, and and note how Facebook divides up real Likes with Facebook registered sites (giving a spash page, #followers, #talking, etc), from Liked urls it does not know. (the site does, at least, get a increasing counter). It kinda defeats the purpose of being Liked at all. I might be wrong, but I think it does not even post messages about the latter.

    this is too bad, because I am running out of phone numbers for Facebook :)

    Then, for me at least, there is a bigger problem. If you are going to reward someone for Liking you, you can't really be sure they did, because this is js. If you try to js redirect to a reward page, a user can just cut paste that url. You could set a rnd session var, pass it to js, and redirect js to a php page with it, but a user could figure that out too.

    You cant seem to (or commented out appId) ...

    require 'face_sdk/face/src/facebook.php';
    $facebook = new Facebook(array(
      'appId' => '',
      'secret' => '',
    ));
    $user = $facebook->getUser();
    

    so there seems no direct php way. I was playing with passing the iframed Like button url to php, parsing it with simple_html_dom.php, and finding which of the two main divs has the class 'hidden_elem'. But in the end, it just isn't worth it because Facebook will treat you like a second class citizen.

    0 讨论(0)
  • 2020-12-02 02:41

    I don't have an appId but just got this code from the like code generator and it seems to work in my local environment (which uses localhost:8000 yet still has 136 likes). When I press the buttons I get the facebook login popup as expected.

    <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";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    
    <fb:like href="url here (optional)" send="true" width="450" show_faces="true"></fb:like>
    
    0 讨论(0)
提交回复
热议问题