Google + 按钮计数显示“0”使用 Sharrre 库 ( Json , Php ).


Google + button counts showing "0" using the Sharrre library ( Json , Php )

所以通过phpinfo()检查,我的服务器上的安全模式已关闭,Curl被激活,没有理由不工作。

我还确保Sharrre.php在我的根目录中。甚至包括了 php 文件中的Curlurl。尝试了绝对和相对链接。带有计数器的谷歌按钮会在上传后立即显示,但不符合预期,因为计数器始终显示 0。

罪魁祸首似乎是:$json = array('url'=>'','count'=>0);

经过几行其他代码,我们得到了这个:

  if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){
    if($type == 'googlePlus'){  //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/
      $contents = parse('https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQurl=' . $url . '&count=true');
      preg_match( '/window'.__SSR = {c: (['d]+)/', $contents, $matches );
      if(isset($matches[0])){
        $json['count'] = (int)str_replace('window.__SSR = {c: ', '', $matches[0]);
      }
    }

所以要么谷歌网址代码不再有效,要么......好吧,也许嫌疑人有问题,因为:

更改为大于 0 的值时$json = array('url'=>'','count'=>15);

如您所见,它显示了 15 个计数。我希望它是动态的,并获取我已经拥有的计数并在每次点击时更新这些计数。

可以做些什么来解决这个问题?

在我的特定情况下,问题在于将 URL 分配给 Curl 对象。原始脚本 sharrre.php 通过将 URL 分配给 curl 对象的数组元素来设置URL,但这不起作用,并导致 Google 计数器无法检索任何数量。相反,URL 必须由 curl_setopt() 函数签名。

这在我的情况下解决了这个问题:

沙雷.php:

//...
$ch = curl_init();
//$options[CURLOPT_URL] = $encUrl;       // <<<--- not working! comment this line.
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_URL, $encUrl ); // <<<--- Yeeaa, working! Add this line.
//...

希望这有帮助。