I am trying to add a facebook like button. I am using the standard XFBML code generated from developers.facebook.com. However, here's the problem: Say my use case is that mail will be sent to customers which will have a link to like my site. Now since you cannot include javascript in emails I have to redirect the user to an intermediate page, which hosts the like button. When the user clicks it he will be either asked to login or will be asked to like it.
I am looking for a way to automatically click the like button when the user clicks on the link from his email. So basically auto-liking the page when he clicks from his email, so that he does not have to click twice - (once on the email link and once on the like button on the intermediate page).The code that I am using is:
<div id="fb-root"></div>
<script>
function f1(d, s, id) {
alert('Function Called');
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=171216266453";
fjs.parentNode.insertBefore(js, fjs);
}
</script>
</head>
<body onLoad="f1(document, 'script', 'facebook-jssdk')">
<div class="fb-like" data-href="http://www.google.com/" data-send="false" data-width="450" data-show-faces="true"></div>
</body>
</html>
AFAIK You cannon automatically click on Like Button on page visit. But you may consider an option of usage iframe version of like button.
Be warned that most online email providers will block it by default and may or may not allow to enable it optionally.
As for JavaScript solution it will be probably stripped out (or user will be warned in bad way) by most email providers and email clients.
Auto liking is not possible for like button. Embedding iframe also will be stripped off due to security reasons.
Related
I have this code to make Facebook share, but this doesn't read my og meta tags. Putting in the Facebook debugger it reads fine.
<h2 class="caixacsstitulo"><%# Eval("titulo") %>
<div class="fb-share-button" data-href="http://www.novaonda.no-ip.info:8080/detalhe_noticia.aspx?id=<%# Eval("id") %>" data-type="box_count">
</div>
<asp:Image ID="Image3" runat="server" Width="32px" ImageUrl='<%# Eval("destaque") %>' Height="32px" ImageAlign="Right" /></h2>
You can access it here
Facebook officially deprecated the share button in favor of the like button earlier this year. A few days ago, I realized that the share button no longer displays on sites I manage. Trying to figure out what could be wrong, I checked those sites using a different browser and it was the same. Still in doubt, I used a different PC and even checked other websites just to be sure.
Across the web, a certain version of Facebook share button stopped working. The Share Button has been deprecated already a while ago but not yet completely dead. If it stops working on your website or blog, you only need to update your code.
Facebook deprecated the Share button on February 28, which means they no longer recommend its use in applications or on external web sites. Also, a certain version of Facebook share button was deprecated several years ago, and Facebook switched to serving the new JS SDK in its place on Monday, July 16. Perhaps the old one will be brought back to life later, but then I guess it’s time to upgrade to the new version. Support has already been dropped for it so there’s no point complaining to Facebook.
How to fix your share button
I prefer using the share button because it lets me share to my fan pages, unlike the like button which Facebook now favors. I found three fixes to this which I think should do the trick.
1. Using the official JD SDK version
Search for http://ogp.me/ns/fb#” just after it. The resulting code should lok like this:
"
If this is already there, you don’t need to do it again.
- In the body of your website where you want the code to display, paste this:
<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=YOUR_APP_ID"; // appId must be valid
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<fb:share-button type="box_count">
</fb:share-button>
Hey, make sure you change these parameters for the code to work:
* YOUR_APP_ID – You must create a facebook application for this code to work. Don’t know how? I explained it on steps 1 and 2 of this post.
* You can change box_count to button_count if you want a smaller button instead of the large one with counter.
Those who have copied the code and pasted on the web page we need to add the class attribute "class="fb-share-button" " to the div that will show the Share button. The automatically generated code from the Facebook is missing this attribute, and that is it does not display the facebook button.
Also, the button appears when the page is loaded or viewed from a web server. If you preview web page on the local computer the while designing it does not show up.
Third thing that you need to check is that there are no errors in loading the js "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5"//
I'm using bellow code, works well for me
<script src="//connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v2.8"></script>
using above code instead of Facebook share-button step 2:
<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/zh_TW/sdk.js#xfbml=1&version=v2.8";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
I am trying to add the facebook like button to an ASP.NET page. I have generated the code with the Get Like Button Code Widget and copied it into my master page. The like button works fine most of the time but for some random pages it doesn't. I have checked for javascript errors using the developer tools javascript console in Chrome but there doesn't seem to be any (I get the same problem in FF and IE as well).
Even more bizarly I can browse to a url such as mysite.com/category/12345/some-descriptive-name and see the problem. But knock a couple of letters off the end of the url (e.g. mysite.com/category/12345/some-descriptive-na) and the problem dissapears [I am using url redirection so as long as the id is the same, the same page is served up].
My best idea was that I was hitting some maximum url length, but that doesn't seem to be the problem as simply changing the Id in the url above works as expected as well.
I have tried both the HTML5 and the XBFML versions of the like button, both with the same problem.
The only other thing I could come up with is generating an appId in the hope that that would make it more reliable.
I am unable to point you to a publicly available site at this time, but the code is below:
...
<body class="clearfix">
<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_GB/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
...
<div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-font="segoe ui"></div>
This SO answer pointed me in the right direction. Using that tool on a link that worked actually caused the like button to stop working on that link further. Looking deeper into the results, there was a redirect section and FB was being redirected to my login page.
This problem was identified on a test site which is locked down. Removing forms authentication temporarily and then running the link through lint resolved the problem.
I have been fighting this for a while, and I just cannot make a facebook 'like' button appear reliably. It appears about 2/3 or 3/4 of the time for me, in any browser, on any page on my site, such as this one: https://www.liveset.com/events/142-blindpilot-new-orleans-live
I'm using the following code:
<div class='fb-like' data-href='https://www.liveset.com/events/142-blindpilot-new-orleans-live' data-layout='button_count' data-send='false' data-show-faces='false'></div>
.
.
.
<div id='fb-root'></div>
<script>
//<![CDATA[
(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>
We've replicated this across numerous browsers and OSs with all extensions disabled. There's only one like button on the page. Our OpenGraph tags are valid, and if they weren't, why would it only fail part of the time?
There are no Javascript errors. all.js loads correctly, and has content. The fb-like div is simply not filled out with an iframe; it remains exactly as it is in the page source. Simply nothing happens.
The problem is easily replicated by visiting the site above and reloading a few times.
I couldnt replicate the issue with 15 reloads, but I have seen this issue quite a few times on sites with alot of dynamic content, or dynamic loading content. Notice how the last thing on your site to load is the facebook button? Likely it is on their end, timing out. I tend to have this issue when other things must load, they take awhile and then facebook cant complete in time for the browser to load it.
* On a side note, trying removing google analytics and quantcast(if you use it) and see if you can replicate the issue then. Let me know.
Try moving your FB script out of your <div id="main"> and into the area below your <div id="footer"> with your other scripts.
It may be because you are dynamically populating content into this div with your Twitter comments wizard, something here is messing up the ability for a browser to parse your Facebook Like button script.
I had developed one small webpage with facebook social plugins (like, recommend and send buttons). I could test the buttons and the click events successfully on localhost till around a month ago; but suddenly the buttons are not working on localhost now. They work only if I deploy the webpage on a public IP through "localtunnel". On localhost, they show the number of likes and names, but don't give a flyout on clicking the button. Also, the subscribed event "edge.create" is not fired.
I have copied all the required javascript from the facebook like button widget page.
I also found out that there is some difference in the traffic pattern on localhost and tunneled deployment. The GET oauth request returns 302 status on localhost while 200 on public domain. Also, the deployment on public domain makes many GET requests after clicking the button to fetch some CSS and images. Whereas the localhost page makes only one request and stops there.
I am not able to understand why this is happening.
Has facebook recently stopped supporting anything required for testing the buttons on localhost?
Complementing on #C-Dan's answer, make sure to have the data-href attribute point to a live site, and not your localhost. That did the trick for me.
I can see likes and like on localhost too (the button and count on my site)
Make sure you have
<html xmlns:fb="http://ogp.me/ns/fb#">
in the html tag
and the actual like div wherever you want in the body -
<div class="fb-like" data-font="verdana" data-href="http://facebook.com/CDanArt" data-layout="button_count" data-send="true" data-show-faces="false" data-width="120" style="margin: 0px 0px 0px 0px;"></div>
and
<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=146351542070012";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
right before your body tag ends.
Of course, use you data-href in the like div and appID in the script function.
This code is working perfectly fine for me on localhost.
If you copy the code as it is and still can't see the like button on localhost, then check if something else is breaking your like button.
I want to add a facebook like social plugin into my Drupal
website. But I'am unable to find the file in which I'll
write the plugin code. Please help me.
You don't need to add any code there is already a module for this http://drupal.org/project/fblikebutton
Simply install the module in your drupal instance.
Cheers,
Vishal
In page.tpl.php between insert this analog with your appcode from 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/en_EN/all.js#xfbml=1&appId=YOUR_APP_NUMBER";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
And in place for Like button insert/ For example inser this in block with PHP filter
<div class="fb-like" data-href="http://yoursite.com/<? echo $_SERVER["REQUEST_URI"]; ?>" data-send="false" data-width="450" data-show-faces="false" data-colorscheme="dark"></div>
FB like button and like box are different.
Like button is to "like" a single page and it comes with an optional inline counter. But Like box is to show who other likes a particular Facebook page. It's appearing as a box.
You can grab the like box code from your facebook page admin UI and put it in a custom block.
http://drupal.org/project/fb_social is a good module that gives a lot of facebook elements.
Facebook like button code - https://developers.facebook.com/docs/reference/plugins/like/
Facebook like box code - https://developers.facebook.com/docs/reference/plugins/like-box/
Add a fb like button - http://drupal.org/project/fblikebutton (or edit node.tpl.php), http://drupal.org/project/sociallinks
Add fb like box - Custom block, http://drupal.org/project/fb_social or page.tpl.php (I recommend to not do this unless this you have a very good understanding in theming. Less configurable)
Like box should be a module. Like button is a node-element.