2

Background: I am making a facebook app where users post messages like in a forum. For that I save the users facebook id to then present their names. I know it is possible to show the name out of a facebook id by using the Graph API, but I can't make it work.

The code I use is the following:

//$fbId is the facebook id to find out the name for

$facebookUrl = "https://graph.facebook.com/".$fbId;
echo(file_get_contents($facebookUrl));
$str = file_get_contents($facebookUrl);
$result = json_decode($str);
echo($result);
return $result->name;

I researched and tested this for hours, but I feel like I'm getting nowhere. I got an idea of how it works from:

http://www.phpexpertsforum.com/how-to-get-the-facebook-name-with-user-id-using-php-code-t1852.html

Didn't work so I researched further from here:

Get user's name from Facebook Graph API

I dowloaded and currently use the Facebook php SDK, but I don't find the way to use it to get anyone's name other than the current user. The problem here seems to be the file_get_contents() function that returns a false, meaning that it can't read the file. I checked out the php documentation. Also, by using the php functions fopen() and file().

//echo(pathinfo($facebookUrl, PATHINFO_EXTENSION)); -> Doesn't give any response!
//echo(file_exists($facebookUrl)); -> No response!
//fopen() doesn't work
//file() doesn't work
//file_get_contents() doesn't work
//tried adding an access token to the $facebookUrl but it doesn't make any difference

Any idea of what could be wrong here? Little guidance would be very helpful. What am I doing wrong? What did I miss?

Community
  • 1
  • 1
Shaffa
  • 23
  • 1
  • 3

1 Answers1

2

Seems that your allow_url_fopen directive is set to Off.

Look for it in your php.ini (or create a php file containing <?php phpinfo(); ?> and point to it in your browser) and check if is set to 'On'.

Esteban
  • 874
  • 8
  • 13
  • You are correct. I am checking out the documentation for my domain provider and it seems that they switched it off. They provided me with a custom file_get_url_contents() function, but it has a protocol problem, so I'll solve it with them. Thanks a lot for the feedback – Shaffa Mar 27 '12 at 20:33