Facebook app: get username from id

I just started the FB application project, and I'm trying to clear a few items before it appears live.

The original programmer has a user ID stored in the database, but does not display his or his name. I would like to display the username under the picture they upload.

My code is <?php echo $row['user_id']; ?> <?php echo $row['user_id']; ?> Is there an easy way to convert it to username?

+7
source share
2 answers

Call the identifier from the API with a name field.

  https://graph.facebook.com/user_id?fields=name 

He must be back

 { "name": "First Lastname", "id": "user_id" } 

Save this for a variable and then extract

  $user['name']; 

For more information http://developers.facebook.com/docs/reference/api/user/

An example without an SDK / access token,

 $response = file_get_contents("https://graph.facebook.com/4?fields=name"); $user = json_decode($reponse,true); echo $user['name']; 

Gotta print

 'Mark Zuckerberg' 
+14
source

try using php api graph 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; 
+1
source

All Articles