i am trying to get the counts for twitter, facebook and google with jquery.getJSON requests starting from the great guide by John Dyer on how do the same with C# and PHP
actually twitter and facebook works but google don't... the json response is:
{
"error": {
"code": 400,
"message": "Required value: id",
"data": [
{
"domain": "global",
"reason": "required",
"message": "Required value: id"
}
]
},
"id": "p"
}
here is the code:
<script type="text/javascript">
function getfbcount(url){
var fblikes;
$.getJSON('http://graph.facebook.com/?ids=' + url, function(data){;
fblikes = data[url].shares;
$('body').append('fb likes ' + fblikes);
});
}
function gettwcount(url){
var tweets;
$.getJSON('http://urls.api.twitter.com/1/urls/count.json?url=' + url + '&callback=?', function(data){
tweets = data.count;
$('body').append('tweets ' + tweets);
});
}
function getplusone(url){
var plusones;
$.getJSON('https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ' + 'callback=?',
{
"method":"pos.plusones.get",
"id":"p",
"params":{
"nolog":true,
"id":url,
"source":"widget",
"userId":"@viewer",
"groupId":"@self"
},
"jsonrpc":"2.0",
"key":"p",
"apiVersion":"v1"
},
function(data){
plusones = data.count;
$('body').append('+1 ' + plusones);
});
}
$(document).ready(function($){
var url = "http://www.google.com"
getfbcount(url);
gettwcount(url);
getplusone(url);
});
</script>
you can't make cross domain requests to the clients6.google.com server. you can see this in your browsers console if you leave out this part:
+ 'callback=?'
twitter and facebook allow these requests...
Do you just need an '&' before 'callback'? At the moment it looks like you are sticking it on to the end of the key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With