Google: Adding Google Plus button to your content pages

Perhaps the best documented out of the social share buttons.

It's quite straight forward if you read the API page.

A simple example with asynchronous loading would be:

<g:plusone></g:plusone>

<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>

That's it!

If you want to configure it, the options are listed on the page under Configuration.

Detecting Plus One Click Event

This is incredibly easy compared to Facebook's API!

<g:plusone callback="googleplus_callback"></g:plusone>

Now in your Javascript function, just check if the state is "on".

function googleplus_callback(response) {
alert(response['state'] == 'on');
}

Ah, so developer friendly!

4e31e0a74eb3d

See my other posts about sharing buttons for Facebook and Twitter.

Sources

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog