-
-
Save MateuszManaj/1d644925a59c7489695cdf15795ff58e to your computer and use it in GitHub Desktop.
Get Google Plus likes count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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