1

Hi i m trying to get url of user's profile pic so I use following code

$userinfo = $facebook->api("/me/picture?type=large");
var_dump($userinfo);

but instead of returning url it returns NULL. Please help me why this is happening.

Thank you.

user392406
  • 1,323
  • 5
  • 28
  • 53

2 Answers2

2

This is how we can get actual picture url

$URL='FB GRAPH API URL';
$headers = get_headers($URL, 1); // make link request and wait for redirection
    if(isset($headers['Location'])) {
      $URL = $headers['Location']; // this gets the new url
    }
    $url_arr = explode ('/',$URL);
    $ct = count($url_arr);
    $name = $url_arr[$ct-1];
    $name_div = explode('.', $name);
    $ct_dot = count($name_div);
    $img_type = $name_div[$ct_dot -1];
    $pos = strrpos($img_type, "&");
    if($pos)
    {
        $pieces = explode("&", $img_type);
        $img_type = $pieces[0];

    }

    $imagename = imgnameyouwant'.'.$img_type;
    $content = file_get_contents($URL);
    file_put_contents("fbscrapedimages/$imagename", $content);
Shailendra Sharma
  • 6,976
  • 2
  • 28
  • 48
0

If you know the [uid], you can simply use the following code

<img src="http://graph.facebook.com/[UID]/picture" />

You can also crop/resize the profile picture by providing height/width parameters.

Eg: https://graph.facebook.com/[UID]/picture?width=140&height=140

If you want to use standard sizes, try

<img src="http://graph.facebook.com/[UID]/picture?type=large" />

where type is one of {square,small,large}

Deepak Thomas
  • 3,355
  • 4
  • 37
  • 39