使用 jquery 获取 google plus 共享数 [英] Getting google plus shares count with jquery

查看:19
本文介绍了使用 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>

这篇关于使用 jquery 获取 google plus 共享数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆