使用 jquery 获取 google plus 共享数
我正在尝试使用 Jquery 获取 URL 的 Google plus 共享计数.
I am trying to get Google plus shares count for a URL with Jquery.
url = 'www.abc.com/';
$.getJSON('https://clients6.google.com/rpc?key=AIzaSyBeAeOUk3BJs9ZXeohJX6Qt2zWXPQsRKRk'+'callback=?',
{
"method":"pos.plusones.get",
"id":"p",
"params":{
"nolog":true,
"id":'http://prince-antil.myshopify.com/',
"source":"widget",
"userId":"@viewer",
"groupId":"@self"
},
"jsonrpc":"2.0",
"key":"p",
"apiVersion":"v1",
},
function(data){
plusones = data.count;
alert(data);
});
但我收到以下错误:
{
"error": {
"code": 400,
"message": "Bad Request",
"data": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
]
},
"id": "p"
}
我创建了一个 API,但我不确定我创建它的方式.上面的错误说无效的密钥".我已经交叉检查了钥匙,但钥匙是正确的.不知道APP区有没有什么特别需要配置的.我是新手.请帮帮我.
I have created an API but I am not sure about the way I have created it. Above error says "invalid key". I have cross checked the key but the key is correct. I don't know if there is something special need to configure in the APP area. I am new bie. Please help me out.
谢谢.
做了一些工作,但这个解决方案成功了.(在 Firefox 和 Chrome 中测试)不需要 API 密钥,也不需要更改.:)不要忘记包含您的 jQuery 文件.
Took some work but this solution did the trick. (Tested in Firefox and Chrome) No API Key required and no changes necessary. :) Don't forget to include your jQuery file.
$(window).load(function(){
/* Social Share: Google Plus JSON */
var data = {
"method":"pos.plusones.get",
"id":"http://www.website_you_want_share_count_for.com",
"params":{
"nolog":true,
"id":"http://www.website_you_want_share_count_for.com",
"source":"widget",
"userId":"@viewer",
"groupId":"@self"
},
"jsonrpc":"2.0",
"key":"p",
"apiVersion":"v1"
};
$.ajax({
type: "POST",
url: "https://clients6.google.com/rpc",
processData: true,
contentType: 'application/json',
data: JSON.stringify(data),
success: function(r){
$('#googleplus_page_share_count').text(format(r.result.metadata.globalCounts.count));
}
});
});
<p><span id="googleplus_page_share_count">256</span> Shares.</p>