Facebook-like button as an overlay to have cross-network liking? - facebook

I have a page that allows users to "like" certain elements. The liking is similar to a facebook-like, but for various reasons (such as being able to easily manipulate the data), the liking is for users of my site, and not necessarily for facebook users, and the data remains on my site. So there is a "mysite-like" button. However, I'd like it if this mysite-like button also functioned as a facebook-like button, and if a person is logged onto facebook, it would post it on their wall.
Is there a way to make a button which performs both functions? E.g. perhaps by having an invisible facebook-like button, overlayed on top of the mysite-like button? Perhaps through some opacity=0 iframe? In an ideal world, clicking on one button would function as a mysite-like, and also a facebook-like, and a google+1. One button to rule them all...

The clean way to do this kind of implementation, where user interaction on a social button triggers changes on your site, is to use the callback methods.
Limitation
These callbacks work in one direction. For example:
Facebook Like button -> your custom 'like' button
OR
Google +1 button -> your custom 'like' button
As a result you will not be able to
trigger either of them from your custom 'like' button
trigger one third party button from the other
And now that you know what you can do with them, here's how to do it.
Facebook Like button callback (from another StackOverflow post)
<script>
FB.Event.subscribe('edge.create', function(href, widget) {
alert('You just liked the page!');
// this is where you would trigger your site specific logic
});
</script>
Google +1 button callback (from the official docs)
<g:plusone callback="myCallback"></g:plusone>
<script>
function myCallback(result) {
alert('button was just changed to state ' + result['state']);
// this is where you would trigger your site specific logic
}
</script>

One way is to have the facebook-like button also trigger a "mysite-like" action e.g. via http://www.saschakimmel.com/2010/05/how-to-capture-clicks-on-the-facebook-like-button/
Is there a way to do this also with google+? You can use the callback option https://developers.google.com/+/plugins/+1button/#plusonetag-parameters but not sure how to get the userid of the user.

Related

2 same fb like buttons on same page - how to find out which was clicked?

I have 2 fb buttons on page. One on top of article and second on bottom. (I would like to test which button people respond better to). Is there any way to find out which button was clicked? maybe using google analytics or any other tool? Thank you.
Use events and callback from Facebook SDK: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.7 edge.create callback return DOM element which FB button was clicked. Then you can use it with analytics events.

facebook show recommend count on mouse over

I am using Addthis plugin. I have an "F" icon on the page. I want it to work as recommend functionality.
is there anyway to do following
if somebody click on F, it should work as recommend is clicked, and on move over this F, it should just show the Count of recommend
we do not want to show standard recommend box with count
Secondly question, when i click on any like button it also show another Share Popup, but even even if i cancel this popup, still my timeline show i have recommended that particular page.. then what is use of that popup.
You can use the Facebook Dialog JavaScript to show a Share dialog for a custom button. Or use the Send Dialog button to create a private share dialog.
The "Comment Box" on the Like Button is optional, it's not required. If you enter a comment, it adds it to the Like post that appears on your timeline. But you can still like a page without entering a comment. A Like with a comment appears more prominent on the user's timeline.

How to trigger Facebook like button from custom button?

I have created a custom Facebook like button.
How do make it that when I click the button, it will trigger the like button provided by Facebook like the one below?
According to facebook policy on Social Plugins point 4 states:
"Don’t obscure or cover elements of social plugins."
You can't change the image directly because it's provided by Facebook.
The Facebook button is in an iFrame with a source that is on a different domain, Facebook’s domain, and so you can't change the button as it's protected by the same-origin policy.
Also, Facebook’s policy prohibits changing their buttons and logos when using embedded content from Facebook, like social buttons.
So, you're not suppose to be able to change the FB buttons, and even if you could it would be against the Facebook Terms of Service.
But... if you still want to do it, you can use the native Facebook button and lay your own image on top or below the Facebook button to fake a custom button.
Laying your image on top is only possible if you use CSS3 pointer-events, wich will make your image click-through and the click event will work "through" your image and actually click the Facebook button.
This only works in newer browsers that support Pointer Events.
Another option is to lay the image behind the FB button and set the FB button's opacity to zero.
I have used this several times myself, and with a little digging around in the Facebook code you can attach hover events and everything else to make it look like a custom button. You would have to find what elements to set opacity : 0 on.
Have never spent any time trying to figure out how to make the unlike function of the original button work on a custom button, but it's probably possible.
All my attempts to actually trigger the FB button with javascript or jQuery trigger() have failed, but maybe someone else has figured out how to do it?
When you create a html element with fb-like class, facebook javascript SDK convert it with a like button when document loaded. You can make a custom element and trigger click event of like button when user click your custom button.
For example :
<input type="button" id="mycustombutton" value="Like">
<div style="display:none" class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
jQuery code:
$("#mycustombutton").click(function(){
$(".fb-like").find("a.connect_widget_like_button").click();
// You can look elements in facebook like button with firebug or developer tools.
});
Update
Facebook SDK has been creating like button in an iframe and browsers not allowing to intervention to the iframe in the page. I think add event listener to element in iframe does not possible anymore.
This is not allowed for the obvious reason that it would lead to fraud. Imagine if each time you clicked an image on the web you don't know if it's an actual image or if it will result in a like and show up in your FB feed. It would be disastrous.
If you do want to do this legitimately, you will need to create an app and have the user authorise the app when he visits your site. This will open a popup where the user agreed to let the app access his FB account. Once that is done you can then send the like request on behalf of the user via a server-side script. In other words, it's not worth the effort.
If on the other hand you just want to get the like count for a page and display it however you want, you can do so via a request to "http://graph.facebook.com/#{url}" which will return a JSON payload with the number of likes. In jQuery it would be:
$.getJSON("http://graph.facebook.com/#{url}", function(data) { alert(data.shares); });
I think that facebook goes through great lengths to make sure people can't trigger the "Like" button. This is to prevent scripts from automatically clicking the "Like" button when someone visits the site.
You may be able to override the style of it using CSS and have your image show instead.
You can overlay your button on top of the Facebook like button and use css to hide the Facebook button.
Not sure on the legalities of this however.
You could try to trigger an Ajax request like this
FB.api(
'me/og.likes',
'post',
{
object: "http://samples.ogp.me/226075010839791"
},
function(response) {
// handle the response
}
);
https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes
http://sharingbuttons.io/ allows to make social media share buttons with no javascript at all (Not a like button like in the question…). For Facebook, it just uses a link like this:
<a href="https://facebook.com/sharer/sharer.php?u=http%3A%2F%2Fsharingbuttons.io"
target="_blank" aria-label="Share on Facebook">Share on Facebook </a><br>Here on Stackoverflow, you have to cmd + click to open the link in a new window.
Customize it with your own CSS and, to mimic the share button, just open the url in a popup instead of a target="_blank".

Facebook Like Button doesn't share

I have add like button on my webpage www.zabavax.com (iframe). Count is work ok, but like button doesn't share post (link) on Facebook.
P.S. Like button on the left side and after post. When i click on right or after post like button liked link dont show on my Timeline and on friends news feed
I think Facebook has changed the behaviour of the like button. A link will be shared ONLY if the user adds a comment.
Your like button in the top right corner of your URL functions correctly.
I was able to post to my profile when I clicked on it.
I believe your issue is with the first-time popup that appears (also with its own like button) When I clicked that like button the popup disappeared and I didn't manage to post to my profile.

Multiple Facebook Like buttons referring same page

I have a page with like button assigned to it. I have some textual contexts on this page, I want to put a Facebook Like button under each text (I do not have different url for each text para on this page).
I want the count to be updated for the page also as user clicks on Like button under any text.
If you can tell me how to hide count near the Like button then also my problem is resolved.
Example: http://www.santabanta.com/trivia.asp?sms=1&catid=1
You could subscribe to edge.create event and reload the buttons after a user clicks like.