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

家住魔仙堡 提交于 2019-11-30 09:34:25

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

redbmk

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);
        }
    );
});
jgillich

Currently, the API does not offer any method to retrieve the +1 count. A workaround would be to fetch it directly from the +1 button like described here (you already linked to it, but I don't think there is another way).

this works for me :

var _url = 'http://mylink.com/';   
$.getJSON('http://anyorigin.com/get?callback=?&url=' + encodeURIComponent('https://plusone.google.com/_/+1/fastbutton?url=' + _url)).done(function(data,status,xhr){
    console.log($(data.contents).find('#aggregateCount').html());
});

Check out the following for another way to get the Google+ count.

http://share.yandex.ru/gpp.xml?url=http://google.com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!