Monday, April 22, 2013

Get Facebook Profile Image By Php

Hi Friends,

Today We Learn About How Upload or Get Facebook Profile image to local server or anywhere you wish.
here we use facebook graph api and facebook sdk to do this task.so please first you have to download FACEBOOK SDK from here Click .After downloading sdk create one facebook application for doing this task login to your facebook account after login your facebook account it print your all details.in this detail also contain your profile image link. Here the question is how to get image link? but is easy by json and file function.

Just create link or url like " $img="https://graph.facebook.com/$user/picture?redirect=false; ".
$user variable contain your facebook id then all these data add to the file_get_contents($img) function then it decode by json like $jd=json_decode($images); and get image url from json like $url=$jd->data->url; and then apply image upload code.this code is used to upload image wia url.

Example Code :

//Get file name by json
     $img="https://graph.facebook.com/$user/picture?redirect=false";   
    $images=file_get_contents($img);
    $jd=json_decode($images);
    $url=$jd->data->url;

   
//create file name;
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = $txt.time();
$name = $name.".".$ext;

 
//file upload
$upload = file_put_contents("uploads/$name",file_get_contents($url));

No comments:

Post a Comment

Thanks....