努力寻找通过jQuery获取Google Plus 1页面的解决方案 – 来自Google隐藏的api的Ajax:
https://clients6.google.com/rpc
此问题也在Stackoverflow link讨论
我的尝试:
$.ajax({ cache: false,type: "POST",url: "https://clients6.google.com/rpc",data: [{ "method":"pos.plusones.get","id":"p","params":{ "nolog":true,"id":"http://www.apple.com",//"id":"http%3A%2F%2Fwww.apple.com","source":"widget","userId":"@viewer","groupId":"@self" },"jsonrpc":"2.0","key":"p","apiVersion":"v1" }],crossDomain: true,jsonp: true,timeout: 5000,dataType: "jsonp",contentType: "application/json; charset=utf-8",success: function (data) { console.log(data); },always: function(data){ console.log(data); } });
结果为chrome:Uncaught SyntaxError:意外的令牌:
在Firefox中:
SyntaxError:missing;在声明之前
{“error”:{“code”: – 32700,“message”:“Parse Error”,“data”:[{“domain”:“g
任何想法如何解决这个问题?
解决方法
您可以使用google plus javascript库来获取共享计数:
包括这些:
<script src="https://apis.google.com/js/plusone.js"></script> <script src="https://apis.google.com/js/client:plusone.js"></script>
然后做:
var params = { nolog: true,id: "http://www.google.com/",source: "widget",userId: "@viewer",groupId: "@self" }; gapi.client.setApiKey('AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ') gapi.client.rpcRequest('pos.plusones.get','v1',params).execute(function(resp) { console.log('count:',resp.result.Metadata.globalCounts.count) });
不要用自己的apikey替换apikey.如果你这样做将无法正常工作.