Php – How get facebook user ID from the application

facebookPHP

I created a facebook application and send request to a user through below code.Now when a user allow my application then i need his id and email address into my canvas url.But on that below code user don't go to my canvas URL.So,Please help me to solve ,how a user go to my canvas url when he allow my application and i get the user id of that user?My code is below:

require_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => '#######',
'secret' => '###################',
'cookie' => true, ));
$req_perms = "publish_stream,offline_access,user_status,email,read_stream";

$session = $facebook->getSession();

$loginUrl = $facebook->getLoginUrl(array('canvas'=>1,'fbconnect' => 0,'req_perms'=>$req_perms));
$me = null;

if (!$session)
{ echo "top.location.href= '$loginUrl';";exit;}

else{

 try {
        $uid    =   $facebook->getUser();
        $me     =   $facebook->api('/me');
     } 
 catch (FacebookApiException $e) 
   { echo "<script type='text/javascript'>top.location.href= '$loginUrl';</script>"; exit;}
}

So,please help me to get the user id.

Thanks in advance

riad

Best Answer

The Facebook ID & email for the current user can be accessed through:

$me['id'];
$me['email'];

Is that what you're after?