It is possible to test "Like" button on localhost?
Not really; facebook has to crawl your site to pull in the title, description, and thumbnail. It can't get to your site if it's on localhost.
Dave's answer is correct, however, I just discovered a workaround: You can make your local machine accessible by using http://localtunnel.me . You'll need to (temporarily) change some URLs used in your app code / html so links point to the temporary domain, but at least facebook can reach your machine.
It is possible to perform limited testing on the facebook like button on localhost. It renders properly on my machine. The trick is using a live, non-localhost URL on the data-href attribute (I used Google in the sample below):
<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/pt_BR/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://www.google.com" data-width="450" data-layout="button_count" data-show-faces="false" data-send="false"></div>
If you're developing the likebutton for www.xyz.com, just add in your hosts file:
127.0.0.1 www.xyz.com
Hooray, no more 500s.
Related
I have followed the exact steps given on facebook developer website, which is to add JS sdk after opening body tag(ideally) and placing the div at the desired place where button should appear.
<body>
<!-- Facebook like button js -->
<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/sdk.js#xfbml=1&version=v2.4";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Add this where you want the button to appear -->
<div class="fb-like" data-href="https://www.facebook.com/myWebsite" data-width="400" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
</body>
After doing this, it would still not show up.
If you don´t run this code on a server (localhost or remote), you need to change the following line:
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";
..to this one:
js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";
I highly suggest NOT doing that though, and using a server on localhost for testing/development.
If that code change does not work, upload it to a real server (without the code change). I just tested it and it works perfectly fine. You should really consider using a real server (or a local one) for development.
Use an editor like Brackets or Webstorm, they all include a server. For example, Brackets is pretty easy for "live editing".
I came across something strange; the Facebok Page Plugin doesn't load on mobile only if it's for a specific Facebook page.
My code:
<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/sdk.js#xfbml=1&version=v2.4&appId=1591121954498982";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-page" data-adapt-container-width="true" data-height="350" data-hide-cover="false" data-href="https://www.facebook.com/pages/סיפורי-פירות-Fruit-Story/410067012494711?fref=ts" data-show-facepile="true" data-show-posts="true" data-small-header="false"> </div>
Changing just this line:
data-href="https://www.facebook.com/pages/סיפורי-פירות-Fruit-Story/410067012494711?fref=ts"
to another page's URL such as:
data-href="https://www.facebook.com/CocaColaUnitedStates?fref=ts"
...makes the plugin load fine.
Is it because the page URL contains Hebrew? Is there a relevant page setting?
I set up a small demo page:
http://s-fruit.co.il/facebook-test.html
Found the cause!
This is an intentional (though peculiar) behavior of Facebook when dealing with age-restricted pages and guest users (not logged in, as it often happens on mobile browsers as most use the app).
Why not simply display a login prompt? Some paraphrased info? Who knows. At least the mystery is solved.
An official response can be found here:
https://developers.facebook.com/bugs/828224027247232/
When I clicked the LIKE or SEND buttons on my site for this link, I get this error:
The page at http://aftersqool.com/a?id=C217EE could not be reached.
Strangely, the page is loading without any issues. The page even has the og tags that Facebook requires.
Anyone know why Facebook is giving this error? What should I do to get the buttons working?
Thanks!
Gus Collazo
AfterSqool.com
You can’t use the Send Button if you’re using Facebook as a Page instead of a Personal Profile.
The Send Button only works with XFBML version of the Like Button; it doesn't work with the iFrame version of the Like Button, per Facebook’s announcement
One more important thing is to provide your facebook page's URL in send and like button. It will defiantly fix it.
If your facebook page URL is: http://www.facebook.com/aftersqool
put this code in it
/*put this code in 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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
/*put this code in site where you want to add it*/
<div class="fb-like" data-href="http://www.facebook.com/AfterSqool" data-width="450" data-show-faces="true" data-send="true"></div>
I could not get Smit Shilu solution to work. I had to remove xfmb=1 to get my buttons to work. Full solution here.
http://metadataconsulting.blogspot.ca/2013/09/facebook-likesend-button-not-working.html
I'm trying to add a facebook like button to my extension.
I've already added a google +1 button but I seem to be having some trouble with the facebook button.
This is the code generated by https://developers.facebook.com/docs/reference/plugins/like/
(Modified the source of the all.js file to be local instead)
<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 = "all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="https://chrome.google.com/webstore/detail/bkonffiagffjhnihbboojciggcplmobc" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
It doesn't show up at all on my extension, and I'm not exactly sure why.
Any tips would be great!
Thanks
The original src value for my like button was something like //connect.facebook.net/en_US/all.js#appId=<number>&xfbml=1. In a chrome extension, this url is extended to chrome-extension://connect.facebook.net/en_US/all.js#appId=<number>&xfbml=1, which will 404. The simple fix is to prepend the original src value with the http protocol, http://connect.facebook.net/en_US/all.js#appId=<number>xfbml=1.
I do not know the specifics of all.js, I can't say if embedding it in your extension will be useful.
(I ran into this same issue and thought I would leave my answer here for others.)
I installed facebook comments on my website. My website is a dynamic website and pages are like this www.example.com/page?id=54, www.example.com/page?id=67
If I post a comment in this page: www.site.com/page?id=54, it also appears in www.example.com/page?id=67. The comments are not unique for a page, but appear in every page. Why is that ?
It seems that FB ignores the ?query part of the URL when retrieving comments.
What you could do: use some form of URl rewriting, so that your URLs are in the form http://www.example.com/page/id/54/ or similar (i.e., appearing to not use the ?id=something query part). That way, the comments should load for each page separately.
Here is a solution that worked for me.
1- Copy this SDK from Facebook. Most probably you already did that.
<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=114215202075258";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
2- Then this
<div class="fb-comments" data-href="http://example.com" data-width="470" data-num-posts="3"></div>
3- The the solution line. Paste these lines of JS at the end. Make sure you do everything in the similar order as I have. It will work, no matter you have a ? in your URL.
<script>
$(".fb-comments").attr("data-href", window.location.href);
</script>