0

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

jono
  • 1
  • 1
  • `perhaps by having an invisible facebook-like button, overlayed on top of the mysite-like button` This is called [clickjacking](https://en.wikipedia.org/wiki/Clickjacking) and and is considered malicious. – abraham May 22 '12 at 02:14

2 Answers2

1

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>
Community
  • 1
  • 1
mimming
  • 13,974
  • 3
  • 45
  • 74
  • I believe that if a users authorizes access an app can post a like with the API. This could be triggered from the +1 callback allowing all three at once. https://developers.facebook.com/docs/reference/api/post/ – abraham May 22 '12 at 02:12
0

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.

jono
  • 1
  • 1