Facebook Graph API won't give me image data

Using PHP 5.2.11 and the new facebook graphic code ...

If i call

$ facebook-> api ("/ me");

I get the correct answer:

array 'id' => string '10700210' (length=8) 'name' => string 'Brandon Renfrow' (length=19) 'first_name' => string 'Brandon' (length=7) 'middle_name' => string '✫' (length=3) 'last_name' => string 'Renfrow' (length=7) 'link' => string 'http://www.facebook.com/brenfrow' (length=32) 'about' => string 'Spiritual birthday: 1/22/2005' (length=29) ... ... 

But if I call

 $facebook->api("/me/picture"); 

I always get the answer:

 null 

Does anyone know why this is?

+6
php graph facebook
source share
6 answers

Well, I think the best answer I found is to call http://graph.facebook.com/USER_ID?fields=picture to get the image url. It’s bad that they don’t document such things on their API, especially when it’s obvious to many people.

+14
source share

As an addition to betaman answer, you can pass parameters in a separate array, for example like this:

 $aResponse = $oFacebook->api('/me', array( 'fields' => 'picture', 'type' => 'large' )); 
+8
source share

You may not even need to make an API call ... use this in your interface:

 <img src="//graph.facebook.com/USER_ID/picture?type=square" /> 

More details here: http://developers.facebook.com/docs/reference/api/#pictures

+6
source share

There is an even simpler way using the provided facebook api, just call:

$facebook->api("/me?fields=picture");

This will make your code simpler and more elegant.

+3
source share

When using $ facebook-> api ("/ me? Fields = picture"); works, you cannot pass parameters such as width or type. Instead, try the following:

 $facebook->api('/me/picture?redirect=false'); 

This worked for me and also allows you to pass parameters.

+1
source share

I just went into my "/ me / picture" in the browser and redirected me to a static image on one of Facebook’s CDN servers. Perhaps redirection throws the key to your air call.

0
source share

All Articles