2013-03-12 30 views
7

我已經嘗試了很多事情,但我無法得到一個適當的API,它會返回我在谷歌加+1計數。如何使用任何API獲得+1計數谷歌加使用任何API

我已經嘗試使用: -

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?

但他們都不是給我的答案。

任何想法....

謝謝:)

+0

可能重複http://stackoverflow.com/questions/ 7403553 /我如何得到一個谷歌加1鍵) – redbmk 2014-01-02 18:05:52

回答

1

目前,API不提供檢索+1計數的任何方法。解決方法是直接從+1按鈕獲取它,如here(您已經鏈接到它,但我認爲沒有其他方法)。

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); 
     } 
    ); 
}); 
+0

這個URL給出了一個404 – 2013-12-19 11:56:39

+0

是的,這是一個非官方的,不支持的方法。看起來網址已經改變,如[在這裏]指出的(http://stackoverflow.com/questions/7403553/how-do-i-get-the-counter-of-a-google-plus-1-button/7409062 #7409062)。它在三月份回來了。 – redbmk 2014-01-02 18:04:39

1

這個工作對我來說:

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()); 
}); 
的[?我如何獲得谷歌加+1按鈕的計數器(