I am new to Facebook and I am trying to write my first app.
I tried the following basic code, and I got to the ‘An error occurred’ part
I understand from that that I got the session but not the user details…
can you please assist me with what went wrong? thanks a lot :
<?php
require 'facebook.php';
//create application instance
$facebook = new Facebook(array(
'appId' => 'XXXXXX',
'secret' => 'XXXXXX',
'cookie' => true,
));
$session = $facebook->getSession();
if (!empty($session))
{
try {
$uid = $facebook->getUser();
$user = $facebook->api('/me');
} catch (Exception $e){}
if (!empty($user)){
if($_GET['installed']=='1'){
header("Location: http://apps.facebook.com/lbsresearch/");
}
echo "Hello user";
}
else {
die ("An error occured");
}
}
else
{
$url = $facebook->getLoginUrl();
echo "<a href='".$url."'>Click here</a> to add this Facebook application";
}
?>
Seems like you are dying before you give the user a chance to log in.
This whole Facebook check is very confusing for me too, i can help you with the code and some comments i use (wrote it once, got it running and reused it everywhere ;))
CALLBACK_URLis where the application is on your server.I hope it will be useful to you 🙂