Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Last active September 27, 2015 20:57
Show Gist options
  • Save necenzurat/1330288 to your computer and use it in GitHub Desktop.
Save necenzurat/1330288 to your computer and use it in GitHub Desktop.
Get Google Plus Followers and Following, yea is messy but it does the job done :)
<?php
/*
* © WTFPL
* by necenzurat
* Updated: 19 May 2013
*/
$id = @$_GET["id"];
//$id = "108520002754793822340";
$link = "https://plus.google.com/u/0/$id/posts?hl=en";
$data = file_get_contents("$link");
//<span role="button" class="a-n S1xjN" tabindex="0">1.001 persoane</span>
function get_my_google_plus_profile($data)
{
// 'have X in circles' element
preg_match('/<span role="button" class="a-n S1xjN" tabindex="0">(.*?)<\/span>/s', $data, $followers);
if (isset($followers) && !empty($followers))
{
$count = $followers[1];
$circles1 = preg_replace('/[^0-9_]/', '', $count);
}
if (empty($circles))
{
$circles = 0;
}
// 'in x circles' element
preg_match('/<span role="button" class="a-n Cl7aRc" tabindex="0">(.*?)<\/span>/s', $data, $following);
if (isset($following) && !empty($following))
{
$count = $following[1];
$circles2 = preg_replace('/[^0-9_]/', '', $count);
}
if (empty($circles))
{
$circles = 0;
}
$return = array('followers' => @$circles1,
'following' => @$circles2
);
return $return;
}
var_dump(get_my_google_plus_profile($data));
@protobyte
Copy link

My God.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment