【问题标题】:how to get the +1 count in google plus using any API如何使用任何 API 在 google plus 中获得 +1 计数
【发布时间】:2013-03-12 17:11:33
【问题描述】:
【问题讨论】:
标签:
javascript
google-api
google-plus
google-plus-one
【解决方案2】:
您可以使用the link you and jgillich mentioned 编写自己的函数。这将使用 jQuery 稍微简化。
这是我作为示例制作的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);
}
);
});
【讨论】:
-
是的,这是一种非官方的、不受支持的方法。如here 所述,URL 似乎已更改。它在三月份开始工作。
【解决方案3】:
目前,API 不提供任何方法来检索 +1 计数。一种解决方法是直接从 +1 按钮中获取它,如 here 所述(您已经链接到它,但我认为没有其他方法)。
【解决方案4】:
这对我有用:
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());
});