【问题标题】:Google Plus API Count Call FailingGoogle Plus API 计数调用失败
【发布时间】:2015-01-28 21:47:02
【问题描述】:

我创建了一个 POST 请求以从 Google Plus 中提取特定 URL 的共享计数,但无法返回任何计数值。

我是否会走很长的路,或者是否有更简单的方法来检索这些数据,例如 Facebook 和 Twitter 提供一个 URL,您将 URL 传递给您想要检索共享计数的 URL,它会返回一个结果JSON 格式!?

GOOGLE_API_KEY 是我从 Google 开发者控制台为Google+ API 获得的密钥的定义变量。

$vRequest = '[{"method":"pos.plusones.get",
    "id":"p",
    "params":{
        "nolog":true,
        "id":"http://www.google.com",
        "source":"widget",
        "userId":"@viewer",
        "groupId":"@self"
    },
    "jsonrpc":"2.0",
    "key":"p",
    "apiVersion":"v1"}]';

$vUrl = "https://clients6.google.com/rpc?key=".GOOGLE_API_KEY;

$vOptions = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n",
        'method'  => 'POST',
        'content' => $vRequest,
    ),
);
$vContext  = stream_context_create($vOptions);
$vResponse = json_decode(@file_get_contents($vUrl, false, $vContext));

我得到的 JSON 响应是:

array(1) { 
    [0]=> object(stdClass)#1 (2) { 
        ["error"]=> object(stdClass)#2 (3) { 
            ["code"]=> int(403) 
            ["message"]=> string(143) "Access Not Configured. The API (+1 API) is not enabled for your project. Please use the Google Developers Console to update your configuration." 
            ["data"]=> array(1) { 
                [0]=> object(stdClass)#3 (4) { 
                    ["domain"]=> string(11) "usageLimits" 
                    ["reason"]=> string(19) "accessNotConfigured" 
                    ["message"]=> string(143) "Access Not Configured. The API (+1 API) is not enabled for your project. Please use the Google Developers Console to update your configuration." 
                    ["extendedHelp"]=> string(37) "https://console.developers.google.com" 
                } 
            } 
        } 
        ["id"]=> string(1) "p" 
    } 
} 

现在我检查了 Google 的 API 控制台,Google+ APIGoogle+ Domains API 都已启用,不知道我还缺少什么。

【问题讨论】:

    标签: php json google-api http-post google-plus


    【解决方案1】:

    这是 Google 尚未向公众提供的私有 API。您的应用程序未列入使用它的白名单。有一个 open feature request 用于获取 URL 的 +1 计数。

    【讨论】:

      【解决方案2】:

      原来我上面使用的代码不再工作了,谷歌在 2013 年做出了改变以阻止它被使用,我现在用来获取大致共享数量的代码如下。

      $vHtml =  @file_get_contents( "https://plusone.google.com/_/+1/fastbutton?url=".urlencode("http://www.google.com"));
      $vDoc = new DOMDocument();
      @$vDoc->loadHTML($vHtml);
      $vCounter = $vDoc->getElementById('aggregateCount');
      echo $vCounter->nodeValue;
      

      在发布此消息时,由于 Google 尚未通过任何 API 提供它,因此无法从 Google Plus 获取共享计数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-21
        • 1970-01-01
        • 1970-01-01
        • 2013-01-02
        • 2013-06-09
        • 2014-11-10
        • 2017-03-02
        相关资源
        最近更新 更多