douyue1998 2013-04-06 10:03
浏览 39

Redirect :: to()清除Facebook访问令牌

I'm building a Facebook app using laravel and I'm using Redirect::to('thank_you') in my code to redirect a user to a thank you page after they've submitted a form.

function submitForm() {
    //Process input
    //Done, now redirect to thank you page
    Redirect::to('thank_you')
}

However, in 'thank_you', the Facebook access token is gone. So when I need to run $facebook->api('/me') it throws an exception saying a valid access token is needed.

It is driving me crazy! Have you got any suggestion for me?

(I'm currently storing the access token in $_SESSION['user_token']. But when the user logs out this is still valid, so the user can't logout of his FB account in the app. And the client doesn't want any logout button on the site)

//Fix for invalid access tokens
if(!isset($_REQUEST['code']) && isset($_SESSION['accessToken'])) {
    $this->facebook->setAccessToken($_SESSION['accessToken']);
} 
//if the user has just done facebook login & auth
else if(isset($_REQUEST['code'])) {
    $_SESSION['accessToken'] = $this->facebook->getAccessToken();
}
  • 写回答

1条回答 默认 最新

  • dougui2254 2013-04-07 10:33
    关注

    If the app is inside an iframe (e.g. a Facebook Canvas App or a Page Tab App) then you need to set a P3P header which tells the browser to allow you to access cookies from within the iframe.

    header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
    

    if you don't do this, the session cookie doesn't get passed to your app, which will result in you being logged out.

    (this is only relevant if you are inside an iframe)

    edit: Here is a good explanation about what the p3p header does Cookie blocked/not saved in IFRAME in Internet Explorer

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)