Skip to content

Instantly share code, notes, and snippets.

@MateuszManaj
Forked from RDIFB0/google_+_likes.php
Created October 9, 2017 12:49
Show Gist options
  • Select an option

  • Save MateuszManaj/1d644925a59c7489695cdf15795ff58e to your computer and use it in GitHub Desktop.

Select an option

Save MateuszManaj/1d644925a59c7489695cdf15795ff58e to your computer and use it in GitHub Desktop.
Get Google Plus likes count.
<?php
function get_gg($url) {
$post_data = json_encode(array(
'method' => 'pos.plusones.get',
'id' => 'p',
'params' => array(
'nolog' => true,
'id' => $url,
'source' => 'widget',
'userId' => '@viewer',
'groupId' => '@self',
),
'jsonrpc' => '2.0',
'key' => 'p',
'apiVersion' => 'v1',
));
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => $post_data,
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://clients6.google.com/rpc', false, $context);
if (is_null($json = json_decode($result, true))) {
return false;
}
return empty($json['result']['metadata']['globalCounts']['count']) ? 0 : intval($json['result']['metadata']['globalCounts']['count']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment