Facebook app redirection : I do have the permissions but i keep gettin empty $session
index.php
require_once ('../src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'cookie' => true,
));
$session = $facebook->getSession();
if (!empty($session)) {
try {
$uid = $facebook->getUser();
$user = $facebook->api('/me');
echo 'session found';
} catch (Exception $e) {}
if(!empty($user)) {
include 'result.php';
}
else {
$url = $facebook->GetLoginUrl(array('canvas' => 1,
开发者_开发知识库 'fbconnect' => 0,
'req_perms' => 'publish_stream, email, user_birthday, user_hometown, user_location, user_religion_politics, user_relationships, friends_about_me, friends_relationships',
'next' => 'http://www.applicationsite.com/index.php',
'cancel_url' => $appCanvasPage ));
#echo 'no user -> link to login';
echo '<a href="'.$url.'">Click here to install the app</a>;
}
}
else {
$url = $facebook->GetLoginUrl(array('canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream, email, user_birthday, user_hometown, user_location, user_religion_politics, user_relationships, friends_about_me, friends_relationships',
'next' =>'http://www.applicationsite.com/index.php',
'cancel_url' => $appCanvasPage ));
#echo 'no session -> link to login';
echo '<a href="'.$url.'">Click here to install the app</a>;
}
?>
choice.php
just to html links to :
http://www.applicationsite.com/index.php?¶m=1
http://www.applicationsite.com/index.php?¶m=1
result.php
<?php
extract($_GET);
if (isset($param)){
I show my result
}
else
{
include 'choice.php';
}
?>
When i first launch the page, i get the "no session" link, so i click and im asked to provide permissions, once i click on "allow", it redirects me to the "choice.php" page, wich means the $params isnt set. thats great.
But when i click on it, i'm back to the index page with the "no session" link, and i have to click on the link again, and then it gets me back to the "choice.php" page. and i keep turning round.
check this one ... I moved the if !empty(user) to the bottom of the page and use if $user... if this wont work then I will give up ^^
require_once ('../src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'cookie' => true,
));
$session = $facebook->getSession();
if (!empty($session)) {
try {
$uid = $facebook->getUser();
$user = $facebook->api('/me');
echo 'session found';
} catch (Exception $e) {}
}
else {
$url = $facebook->GetLoginUrl(array('canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream, email, user_birthday, user_hometown, user_location, user_religion_politics, user_relationships, friends_about_me, friends_relationships',
'next' =>'http://www.applicationsite.com/index.php',
'cancel_url' => $appCanvasPage ));
#echo 'no session -> link to login';
echo '
<a href="'.$url.'">Click here to install the app</a>';
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta charset="UTF-8"/>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<title>test</title>
<link rel="stylesheet" href="../styles.css" type="text/css" media="screen" />
</head>
<body>
<div id="fb-root"></div>
<?php if ($user){ ?>
<!-- whatever you want to put on the website just for user goes here-->
<div class="whatever">
<?php include "result.php";?>
</div>
<?php } ?>
</body>
</html>
精彩评论