Facebook Like Button on Google Chrome Extensions - facebook

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.)

Related

Facebook like (button count) not visible on my website

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".

Where does app_id in facebook's sharer.php come from?

I am using facebooks's share button, exactly as specified in https://developers.facebook.com/docs/plugins/share-button/.
I tried the HTML5 and XFBML versions, but both generate the link below, which returns http error 500 when the user submits. If I manually remove the app_id parameter (which I did not inform anywhere), it works perfectly.
https://www.facebook.com/sharer/sharer.php?app_id=309437425817038&sdk=joey&u=http%3A%2F%2Fg1.globo.com%2Feconomia%2Fnoticia%2F2014%2F05%2Fministro-da-fazenda-diz-que-nao-vai-faltar-energia-no-pais.html&display=popup
I am using this from my company's intranet, to share a link from the company's external website.
This is my code:
<!-- Facebook -->
<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/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<fb:share-button href="<SHARED_URL>" type="button_count"></fb:share-button>
<!-- <div class="fb-share-button" data-href="<SHARED_URL>" data-type="button_count"></div>-->
So where does this app_id comes from? How do I get rid of it? I want to use the button with the share count, therefore I wouldn't like to call sharer.php directly.

Facebook Like button 404 error for connect.facebook.net/en_US/all.js

When trying to add a Facebook like button, my browser is getting a 404 error when attempting to load the FaceBook SDK from: connect.facebook.net/en_US/all.js
Chrome developer tools shows the following:
GET http://connect.facebook.net/en_US/all.js#xfbml=1 404 (Not Found)
Referencing: https://developers.facebook.com/docs/reference/plugins/like/
I inserted the following right before <body> tag:
<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>
Then I added the following where I wanted my like button:
<div class="fb-like" data-href="http://developers.facebook.com/docs/reference/plugins/like" data-send="false" data-width="450" data-show-faces="false"></div>
Note: Using the default dev test data-href as an example.
I noticed that it worked when I accessed my page from another network.
Digging into it further, I found that it was a firewall on our network that was blocking requests to connect.facebook.net/en_US/all.js.

Error Displaying Facebook Social Plugins

Im having problems using the Facebook social plugins. If its important, I use GWT to display the code inside an HTML widjet
I put this in my html
<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:comments width="600" num_posts="2" href="http://www.woojah.com"></fb:comments>
And nothing is displayed. However, if I open the source code with firebug, and I cut that code and paste it again, it is displayed. It is as if that code needs a special "refreshing" or "reloading". By the way, I got that code from the developers.facebook.com page. It's the social plugin comment code.
Also my html tag is <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
So my question is: Does anyone know why the comment plugin is not displayed and why, when I cut and paste the exact same code with firebug it is displayed.
You may want to look into using the FB.XFBML.parse() command to have the SDK reparse the page after you use GWT to insert the code inside your widget.

Facebook comments, for each page

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>