dtkyayvldeaqhl7151 2015-01-28 21:47
浏览 64
已采纳

Google Plus API计数调用失败

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.

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 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
",
        'method'  => 'POST',
        'content' => $vRequest,
    ),
);
$vContext  = stream_context_create($vOptions);
$vResponse = json_decode(@file_get_contents($vUrl, false, $vContext));

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" 
    } 
} 

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.

  • 写回答

2条回答 默认 最新

  • douliao2493 2015-01-29 16:24
    关注

    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;
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行