I just had a FB app project turned over to me, and I'm trying to clean up a few items before it goes live.
The original programmer has the user ID number stored in the database, but doesn't display it or the name. I'd like to display the user's name under the picture they upload.
My code is <?php echo $row['user_id']; ?>
, is there a simple way to convert that into the user's name?
Call the id from the API with the name field.
https://graph.facebook.com/user_id?fields=name
It should return
{
"name": "First Lastname",
"id": "user_id"
}
Save that to a variable and then extract
$user['name'];
For more information http://developers.facebook.com/docs/reference/api/user/
An example without the SDK/access token,
$response = file_get_contents("https://graph.facebook.com/4?fields=name");
$user = json_decode($reponse,true);
echo $user['name'];
Should print,
'Mark Zuckerberg'
try using the php graph api like this:
$facebook = new Facebook(array(
'appId' => "your appID",
'secret' => "your app secret",
'cookie' => true,
));
$answer = $facebook->api("/{$row[user_id]}");
$username = $answer['name'];
print $username;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With