我搜索了几个小时的工作解决方案,通过js调用获得谷歌加按钮计数。
这是我的解决方案:
<script>
function handleClientLoad(){
var params = {
nolog: true,
id: "http://www.google.de/",
source: "widget",
userId: "@viewer",
groupId: "@self"
};
gapi.client.rpcRequest('pos.plusones.get', 'v1', params).execute(function(resp) {
console.log('count:', resp.result.metadata.globalCounts.count)
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
答案 0 :(得分:0)
THIS链接可能是你,示例有php curl示例,但curl URL也可以使用JS ajax调用。
修改强>
$.ajax({
url: "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ",
data: {"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"} ,
dataType : json
success: function(res){
console.log(res);
//[0]['result']['metadata']['globalCounts']['count']
}
});