问题
My application refreshs automatically to facebook login url but my user already signed in so repeats refresh, nonstop.
Here is my code
$facebook = new Facebook(array(
'appId' => 'my app id',
'secret' => 'my secret key',
'cookie' => true,
));
$session = $facebook->getSession();
$fbme = null;
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'next' => 'my app uri',
'cancel_url' => 'my app uri',
'req_perms' => 'email,publish_stream,status_update,offline_access,user_birthday'
)
);
if (!$session) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
else {
try {
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
}
function d($d){
return TRUE;
}
And my page's source in refresh is:
"<script type='text/javascript'>top.location.href = 'facebook login url..';</script>
Always refreshs, non stop.
I looked google and i found p3p policy: header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
added but not working :(
Sorry for my bad English.
回答1:
I guess you need to look at this document:
Cookies in iframes/P3P Header
Some browsers will let iframes set cookies based on the presence of the P3P header. Notably, IE respects this header. Ideally you may want to look up the right value based on the privacy policy adopted by your application, but any value will usually suffice. The sample application sends this for instance:
P3P: CP="HONK"
回答2:
- Download the latest version of the PHP-Sdk form My Apps -> your application
- Disable the option Stream post URL security in My App->your application->Edit Settings.
You might be using the old version of the PHP Sdk.
来源:https://stackoverflow.com/questions/5083484/facebook-application-refresh-automatically