Google Plus API计数呼叫失败 [英] Google Plus API Count Call Failing

查看:173
本文介绍了Google Plus API计数呼叫失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个POST请求,用于从Google Plus中获取特定网址的份额,但无法获得任何返回的计数值。

I've created an POST request to pull the share count for a specific URL from Google Plus but have been unable to get any count value returned.

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

Am I going the long way about it or is there an easier way to retrieve this data, for example Facebook and Twitter supply a URL that you pass the URL to that you want to retrieve the share count for and it returns a result in a JSON format!?

GOOGLE_API_KEY id是Google开发人员控制台为<$ c $获得的密钥的已定义变量c> Google+ API 。

GOOGLE_API_KEY id a defined variable of the key I've gotten from Google's developer console for 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响应是:

The JSON response I get back is:

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+ API Google+ Domains API ,不知道我还缺少了什么。

Now I've checked Google's API console and both Google+ API and Google+ Domains API are both enabled, not sure what else I'm missing.

推荐答案

原来我上面使用的代码已经不再适用了,Google在2013年做了一个修改来阻止它正在使用,我现在使用的代码来获取近似份额计数。

Turns out the code I was using above doesn't work any more, Google made a change in 2013 to block it being used, the code I'm using now to get the approximate share count is below.

$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 Plus无法从Google避风港获取份额不会通过任何API提供它。

At the time of posting this there is no way to get the share count from Google Plus as Google haven't made it available via any API yet.

这篇关于Google Plus API计数呼叫失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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