I am currently trying to make a login with Facebook for my website.
Currently I have just made a simple app, which should echo out the users first name, but it just redirects me to http://facebook.com/
EDIT: I here is my PHP source, of my example:
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 "<script>top.location.href= '$loginUrl';</script>";exit;}
else{
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
}
catch (FacebookApiException $e)
{ echo $me['firstname']; exit;}
}
?>
EDIT: I have made a remake, to upgrade the getSession() to the getUser().
But it is still just redirecting to Facebook’s home page. Any ideas?
New source:
<?php
require_once("facebook.php");
$config = array();
$config[‘appId’] = '116624645175305';
$config[‘secret’] = 'a6b557e6d703328d0cac9db47b20ae98';
$config[‘fileUpload’] = false; // optional
$config[‘cookie’] = true;
$facebook = new Facebook($config);
$req_perms = "publish_stream,offline_access,user_status,email,read_stream";
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(array('canvas'=> 1,'fbconnect' => 0,'req_perms' => $req_perms));
$user_info = null;
if (!$user) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";exit;
}else{
try {
$user_info = $facebook->api('/me');
}
catch (FacebookApiException $e) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>"; exit;
}
}
?>
Facebook SDK for PHP has no method getSession();