@motyar

I'm Motyar, an entrepreneur and API developer from India

Creating value through Programming

DigitalOcean Cloud hosting for developers
20GB SSD, 512MB RAM - only $5 per month

Sep 29, 2011

Fetch Google Plus Profile Picture using PHP

Google plus APIs are out now, you can fetch profile images or avatar using that too. But I am here to show you how you can fetch google plus profile image without using their API. Simple and short, and no call limit.

Profile URL schema

Before launching the Google plus, Google's user profiles URL schema was something like this
http://profile.google.com/GoogleIdHere, For example my Google profile link was https://profile.google.com/dharmmotyar or https://profile.google.com/116599978027440206136

On Google Plus its https://plus.google.com/116599978027440206136

Profile Image URL schema

Ok lets talk about profile image, You can get a profile image by ID (or mail ID too) here is the url
https://profiles.google.com/s2/photos/profile/GoogleIdHere, mine is https://profiles.google.com/s2/photos/profile/116599978027440206136
Note: This is not the permalink to profile picture, this will redirect you.

Using PHP to get Picture URL

Its simple with PHP, we are just fetching where its redirecting us, we are going to use a old trick, here is the code:

$headers = get_headers("https://profiles.google.com/s2/photos/profile/".$id, 1);
$PicUrl = $headers['Location'];

You can use it for mail id like this

$email                  =      "something@gmail.com";
list($id, $domain) = split("@",$email);
$headers = get_headers("https://profiles.google.com/s2/photos/profile/".$id, 1);
$PicUrl = $headers['Location'];

You can Discussion and Commets on Google plus

Labels: , , , ,


By :