PaulEx10 PaulEx10 - 2 months ago 5
PHP Question

Get FB Full Name by ID

Is it possible to get somebody's Facebook name by ID?

It's possible to get it by file_get_contents but it's disabled on my server I'm afraid. I believe there's a curl work around but I've not used much curl before so I'm not quite sure what to use.

$pageContent = file_get_contents('http://graph.facebook.com/1157451330');
$parsedJson = json_decode($pageContent);
echo $parsedJson->name;


Any help is greatly appreciated.

Answer

You can use cURL, like so:

$url = 'http://graph.facebook.com/4?fields=name';

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_URL,$url);
$result = curl_exec($ch);
curl_close($ch);

$result = json_decode($result);
echo $result->name;

Output:

Mark Zuckerberg
Comments