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

3

6

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 use the limited version with an iFrame.

However, now I'm trying to figure out the XFBML method and the online documentation seems to make a lot of assumptions about what you already know and really short on working examples. For example, they show you how to call the JavaScript Init and give you the single line of HTML code for element fb:like... but I could not see any examples of how to show/hide faces, set the default font, etc. like in the iFrame code.

I've since figured out that you need to add them as attributes to the element but that was thanks to StackOverlfow and no thanks to the Facebook documentation which simply takes you in circles.

<fb:like href="http://mydomain.com" show_faces="true" action="recommend" colorscheme="light" width="400" height="35" />

Ok, so now when using the XFBML code, it's height should expand/contract automatically depending on being logged in or not I assume.

I do not know if I'm supposed to initially set the height to "80" or if that happens automatically.

And I have no idea what I'm supposed to use for 'your app id' in the Init script. There is no App... just a Facebook Company Page... so why would I need an App Id when I'm just putting a Like button on a website?

<script>
window.fbAsyncInit = function() {
  FB.init({
    appId: 'your app id',
    status: true,
    cookie: true,
    xfbml: true
  });
};

Any enlightenment on these issues would be appreciated.

Thank-you!

Castoff answered 7/4, 2011 at 0:14 Comment(0)
C
15

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.

Castoff answered 7/4, 2011 at 1:22 Comment(2)
Leaving off the appId=3990840334890 seems to work just finePalliative
@PeterEhrlich I guess you will just be missing stats/insights, when not providing an appId. Seems to work for me as well. Event with comments plugin...Preuss
C
1

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>
Cauliflower answered 3/7, 2012 at 21:4 Comment(0)
C
0

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.

Centrifugate answered 26/2, 2013 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.