-1

I am creating an app where a lot of facebook friends are loaded once the user is logged in. Then the app shows a list of these users where I want to show a small square profile picture next to each user.

I found this url to do that:

http://graph.facebook.com/4/picture?type=square

by checking the app, all data is loaded within 1 second, but it takes almost 10 to 20 seconds to show all images because of the url translation from graph.facebook.com to the original url.

so I went checking the manuals, and found more info regarding receiving the url as JSON, what I could use in PHP to store the direct url of that square picture, so it will not be translated every time I reload the app.

so the next url gives me that JSON:

http://graph.facebook.com/4/picture?type=square&redirect=false

this url will give me this as output in my browser:

{
   "data": {
      "is_silhouette": false,
      "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/p50x50/10390028_10102210419817761_5871103530921178170_n.jpg?oh=8113088106568f3a88016bcf414ba67f&oe=56C5FA23&__gda__=1455882568_659558fb576ed2425347df8a208cbca4"
   }
}

the next step was to get the url out of that JSON, what I try to do using this code

$url = 'http://graph.facebook.com/4/picture?type=square&redirect=false';
echo json_decode(file_get_contents($url))->url;

the strange thing is now, after a lot of trial & error, everytime I use file_get_contents, all ECHO text is gone, even if I do somewhere something like echo "test" , that echo is also gone. Even if I store that output to a variable, it is still empty. Can anyone show me what I do wrong? thank you.

The goal is.. once the user is logged on.. to store username, user id and the url to that square user picture in a temporary location until the session is broken, just to get the load performance better

haypro
  • 85
  • 13
  • _“all ECHO text is gone, even if I do somewhere something like echo "test" , that echo is also gone”_ – that means that you should first of all enable proper error reporting, so that PHP can tell you where _you_ messed up – see http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851 – CBroe Oct 20 '15 at 08:50
  • Hi, this was indeed the cause, this had nothing to do with file_get_contents itself, but a wrong IF statement what messed up the entire script, thank you – haypro Oct 27 '15 at 11:17

1 Answers1

0

Analyse the URL's answer..

{
   "data": {
      "is_silhouette": false,
      "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/p50x50/10390028_10102210419817761_5871103530921178170_n.jpg?oh=8113088106568f3a88016bcf414ba67f&oe=56C5FA23&__gda__=1455882568_659558fb576ed2425347df8a208cbca4"
   }
}

You're doing it the wrong way. It's not json_decode(file_get_contents($url))->url; but json_decode(file_get_contents($url))->data->url;

So, instead of:

$url = 'http://graph.facebook.com/4/picture?type=square&redirect=false';
echo json_decode(file_get_contents($url))->url;

Make it:

$url = 'http://graph.facebook.com/4/picture?type=square&redirect=false';
echo json_decode(file_get_contents($url))->data->url;
Luis Ávila
  • 689
  • 4
  • 14
  • thank you for this information. What I discovered now was that the info is stored if I replace that echo with a variable. I cannot echo that variable, but if I store this, the url value is visible in that temporary text file. Do you know why the echo is not showing ? – haypro Oct 19 '15 at 23:09
  • Not really, it shows for me... Are you using this exact code? @haypro – Luis Ávila Oct 19 '15 at 23:17
  • Hi, yes I used this exact code, but due to a wrongly written IF statement, all output was gone. So your responses helped – haypro Oct 27 '15 at 11:19