T
T
tvsjke2017-07-25 11:15:04
PHP
tvsjke, 2017-07-25 11:15:04

How to get google plus shares count?

Note:
Actually, the problem is in the title. The method used before now (for some reason) does not work:

$endpoint = 'https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=' . $url;
  $session = curl_init($endpoint);
  curl_setopt($session, CURLOPT_RETURNTRANSFER, TRUE);
  $result = curl_exec($session);
  curl_close($session);
  $tmp = [];
  preg_match('#<div id="aggregateCount" class="Oy">(.+?)</div>#is', $result, $tmp);

  return $tmp[1];

Googling only returns combinations with the above url, which don't
work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tvsjke, 2017-07-26
@tvsjke

Found. Maybe someone will need:

$url = 'url';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$curl_result = curl_exec($curl);
curl_close($curl);

$json = json_decode($curl_result, true);
$shares = $json[0]['result']['metadata']['globalCounts']['count'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question