Reputation: 2080
i am trying to write a Facebook application where once installed on a page provides a simple Form once this form is populated it would create a new table with this users username or userid.
So far i have the FBML form up and running using an external php file to process it all how can i get users username or userid to my forms php action file.
Upvotes: 1
Views: 850
Reputation: 2246
Are you using the PHP SDK or the javascript SDK? If you're using the PHP SDK, it's as simple as this:
require_once("facebook.php");
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
$user = $facebook->getUser(); // This is the FB user ID
$username;
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$username = $user_profile['username']; // this is the facebook username.
// If the user hasn't set it manually, it will be something
// like "john.doe.50"
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Upvotes: 2