Alex Rivera | Logout

Get user's name from Facebook Graph API

Asked 2011-04-26T10:22:13.687
19

I would like to know how is it possible to retrieve a string from an external page.

For example: In a PHP website, the user sends a facebook id, ex: 1157251270

And the website returns the name from http://graph.facebook.com/1157251270.

I hope I made it clear.

Thank you

Edit
Report

1 Answer

2

Either you use :

$res_json = file_gets_contents("http://graph.facebook.com/1157251270")
$res = json_decode($res_json)

Or, if you prefer curl (here with https and access token) :

$ch4 = curl_init();
curl_setopt($ch4, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch4, CURLOPT_URL, "https://graph.facebook.com/1157251270?access_token=YOUR_ACCESS_TOKEN");
curl_setopt($ch4, CURLOPT_SSL_VERIFYPEER, false);

if(!$result = curl_exec($ch4))
{
    echo curl_error($ch4);
} else {
    $res = json_decode($res_json)
}

curl_close($ch4);
answered 2011-04-26T10:32:43.617

Your Answer