I'm writing a Facebook application which fetches some info about the user and does some manipulations on it.
I get the user permissions li开发者_JAVA技巧ke this:
$facebook = new Facebook(array(
'appId' => APPID,
'secret' => 'APPSECRET',
));
$logoutUrl = $facebook->getLogoutUrl();
(The default permission is for user_info)
$user_profile = $facebook->api('/me');
After the user logs in, the application goes through several PHP pages, and in the shows a msg. In the last PHP page, I try to get once again the user info.
$facebook = new Facebook(array(
'appId' => APPID,
'secret' => 'APPSECRET',
));
$logoutUrl = $facebook->getLogoutUrl();
$user_profile = $facebook->api('/me');
My problem is that on some browsers (Chrome) it works, and on other browsers (IE) it doesn't.
I get an Oauth exception that I don't have a valid authentication key.Can you see why is that?
The thing is very simple:
First you init facebook:
$facebook = new Facebook(array(
'appId' => APPID,
'secret' => 'APPSECRET',
));
Then you get the user
$user = $facebook->getUser();
And finally you test if there a user or not, if there you do all the request to the facebook api and generate the logout url, if not you get the login url and redirect the browser to that url.
if ($user){
$user_profile = $facebook->api('/me');
$logoutUrl = $this->facebook->getLogoutUrl();
else{
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email,user_birthday'));
echo '<script type="text/javascript">top.location.href = "'.$loginUrl.'"</script>';
}
This should work for all browsers because I tested, so good luck.
kick off the authentication flow in such a case. and if this still happens, see if this is realted to cookies settings.
try to set the header properly.
精彩评论