Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the +1 count in google plus using any API

I have tried many things but I'm not able to get a proper API which will return me the +1 count in google plus.

I have already tried using :-

Getting Counts for Twitter links, Facebook likes and Google +1 with Jquery and AJAX

Getting Google+ subscription count with jQuery

How do I get the counter of a google plus +1 button?

But none of them is giving me the answer.

Any thoughts....

Thanks :)

like image 940
Aamir Shah Avatar asked Mar 12 '13 17:03

Aamir Shah


2 Answers

i just found out a very useful site to solve our problem. :) Thanks to him! http://99webtools.com/script-to-get-shared-count.php

like image 117
bonbon.langes Avatar answered Sep 17 '22 18:09

bonbon.langes


You could write your own function using the link you and jgillich mentioned. This would be slightly simplified with jQuery.

Here's a jsfiddle I made as an example. You'll probably have to use something like PHP to fetch from the site if you want to circumvent inter-domain issues. It could look something like this though (ignoring domains):

$('#myInput').keyup(function () {
    var url = 'https://plusone.google.com/_/+1/fastbutton?url=' + encodeURIComponent($(this).val());
    $.get(url,
        function (data) {
            var aggregate = $('#aggregateCount', data).html(),
                exactMatch = $('script', data).html().match('\\s*c\\s*:\\s*(\\d+)');

            $('div').html(exactMatch ? exactMatch[1] + ' (' + aggregate + ')' : aggregate);
        }
    );
});
like image 39
redbmk Avatar answered Sep 21 '22 18:09

redbmk