我花了几个小时寻找一个可行的解决方案,通过 js 调用获取 google plus 按钮计数。
这是我的解决方案:
<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>
最佳答案
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']
}
});
关于javascript - 如何通过 AJAX 调用获取 google plus 按钮计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25865280/