Motyar

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 :

6 comments

#

Anonymous SenthilKumar says…

How to get google profile picture .... if user have not join google+, i tested ur code with some gmail ids, it shows NULL.... pls help me to get Google Profile Photos via PHP
 
#

Anonymous andy says…

thanks got good info
 
#

Blogger Prabhu says…

Nice .. It is working fine
 
#

Blogger praveena says…

If anyone wants a thumbnail out of the profile
https://profiles.google.com/s2/photos/profile/116599978027440206136?sz=48

 
#

Anonymous pH4Lk0n says…

Unfortunately your version of fetching profile image by email is no longer working :(
 
#

Blogger Armin says…

where sholud I have define profile ID? What's the exact php code to show the image?
Thanks
 

Post a Comment