使用jquery获取google plus共享计数

使用jquery获取google plus共享计数,jquery,api,google-plus,Jquery,Api,Google Plus,我正试图通过Jquery获得一个URL的Google plus共享数 url = 'www.abc.com/'; $.getJSON('https://clients6.google.com/rpc?key=AIzaSyBeAeOUk3BJs9ZXeohJX6Qt2zWXPQsRKRk'+'callback=?', { "method":"pos.plusones.get", "id":"p", "params":{ "nol

我正试图通过Jquery获得一个URL的Google plus共享数

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,但我不确定我创建它的方式。上面的错误表示“无效密钥”。我核对过钥匙,但钥匙是正确的。我不知道应用程序区域是否需要配置一些特殊的东西。我是新来的。请帮帮我

谢谢。

“p”
肯定不正确

您在URL中提供了一个更真实的键,但用这个伪键覆盖了它

将其放在数据数组中:

$.getJSON('https://clients6.google.com/rpc?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":"AIzaSyBeAeOUk3BJs9ZXeohJX6Qt2zWXPQsRKRk",
       "apiVersion":"v1",         
    },
    function(data){          
       plusones = data.count;
       alert(data);
    }
);
“p”
肯定不正确

您在URL中提供了一个更真实的键,但用这个伪键覆盖了它

将其放在数据数组中:

$.getJSON('https://clients6.google.com/rpc?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":"AIzaSyBeAeOUk3BJs9ZXeohJX6Qt2zWXPQsRKRk",
       "apiVersion":"v1",         
    },
    function(data){          
       plusones = data.count;
       alert(data);
    }
);

做了一些工作,但这个解决方案成功了。(在Firefox和Chrome中测试)无需API密钥,无需更改: 不要忘记包含jQuery文件

$(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>
$(窗口).load(函数(){
/*社交分享:谷歌+JSON*/
风险值数据={
“方法”:“pos.plusones.get”,
“id”:”http://www.website_you_want_share_count_for.com",
“参数”:{
“nolog”:没错,
“id”:”http://www.website_you_want_share_count_for.com",
“源”:“小部件”,
“userId”:“@viewer”,
“groupId”:“@self”
},
“jsonrpc”:“2.0”,
“键”:“p”,
“apiVersion”:“v1”
};
$.ajax({
类型:“POST”,
url:“https://clients6.google.com/rpc",
processData:对,
contentType:'应用程序/json',
数据:JSON.stringify(数据),
成功:功能(r){
$('#googleplus_page_share_count').text(格式(r.result.metadata.globalCounts.count));
}
});
});
256股


做了一些工作,但这个解决方案成功了。(在Firefox和Chrome中测试)无需API密钥,无需更改: 不要忘记包含jQuery文件

$(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>
$(窗口).load(函数(){
/*社交分享:谷歌+JSON*/
风险值数据={
“方法”:“pos.plusones.get”,
“id”:”http://www.website_you_want_share_count_for.com",
“参数”:{
“nolog”:没错,
“id”:”http://www.website_you_want_share_count_for.com",
“源”:“小部件”,
“userId”:“@viewer”,
“groupId”:“@self”
},
“jsonrpc”:“2.0”,
“键”:“p”,
“apiVersion”:“v1”
};
$.ajax({
类型:“POST”,
url:“https://clients6.google.com/rpc",
processData:对,
contentType:'应用程序/json',
数据:JSON.stringify(数据),
成功:功能(r){
$('#googleplus_page_share_count').text(格式(r.result.metadata.globalCounts.count));
}
});
});
256股


您需要用符号(&)将API密钥参数与回调参数分开。但是,这仍然不起作用,因为G+API不接受JSONP并拒绝回调参数。您需要使用符号(&)将API键参数与回调参数分开。但是,这仍然不起作用,因为G+API不接受JSONP并拒绝回调参数。