javascript 如何使用任何 API 在 google plus 中获得 +1 计数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15367687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 00:33:29  来源:igfitidea点击:

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

javascriptgoogle-apigoogle-plusgoogle-plus-one

提问by Aamir Shah

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.

我尝试了很多东西,但我无法获得合适的 API,它会在 google plus 中返回 +1 计数。

I have already tried using :-

我已经尝试过使用:-

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

使用 Jquery 和 AJAX 获取 Twitter 链接、Facebook 喜欢和 Google +1 的计数

Getting Google+ subscription count with jQuery

使用 jQuery 获取 Google+ 订阅数

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

如何获取 google plus +1 按钮的计数器?

But none of them is giving me the answer.

但他们都没有给我答案。

Any thoughts....

有什么想法吗....

Thanks :)

谢谢 :)

回答by bonbon.langes

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

我刚刚发现了一个非常有用的网站来解决我们的问题。:) 谢谢他! http://99webtools.com/script-to-get-shared-count.php

回答by redbmk

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

您可以使用您和 jgillich 提到的链接编写自己的函数。这将通过 jQuery 稍微简化。

Here's a jsfiddleI 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):

这是我作为示例制作的jsfiddle。如果您想规避域间问题,您可能必须使用 PHP 之类的东西来从站点获取数据。它可能看起来像这样(忽略域):

$('#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);
        }
    );
});

回答by Kenabeach

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

回答by 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).

目前,API 不提供任何方法来检索 +1 计数。一种解决方法是直接从像描述的+1按钮把它拿来这里(你已经链接到它,但我不认为这是另一种方式)。

回答by jivinivan

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

查看以下内容,了解获取 Google+ 计数的另一种方法。

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

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