1
// GET "giris-yap/facebook"
public function action_facebook_index()
{
    $facebook = IoC::resolve('facebook-sdk');
    $user = $facebook->getUser();

    if($user)
    {
        $profile = $facebook->api('/me');

        return View::make('home.login-facebook')
            ->with('message_area', null)
            ->with('username', $profile['username']);
    }
    else
    {
        return Redirect::to($facebook->getLoginUrl(array('next' => 'http://dugun.dev/giris-yap/facebook')));
    }
}

// POST "giris-yap/facebook"
public function action_facebook_process()
{
    $facebook = IoC::resolve('facebook-sdk');
    $user = $facebook->getUser();
    $profile = $facebook->api('/me');

    $input = Input::all();

    Auth::attempt(array('username' =>  $profile['username'], 'password' => $input['password']));

    if(Auth::check())
        return Redirect::to('account');
    else
        return View::make('home.login-facebook')
            ->with('message_area', 'Giriş denemesi başarısız.')
            ->with('username', $profile['username']);
}

上面的代码在我的机器上完美运行,但我的朋友在 Chrome 和 Firefox 上都出错了。

Chrome:错误 310 (net::ERR_TOO_MANY_REDIRECTS):重定向太多。

Firefox:Firefox 检测到服务器正在以永远不会完成的方式重定向对该地址的请求。

它发生在这一行:

return Redirect::to($facebook->getLoginUrl(array('next' => 'http://dugun.dev/giris-yap/facebook')));

理论上; 我重定向到 Facebook,然后 Facebook 重定向回action_facebook_index(),然后重复。但是,Facebook 不应该重定向它。它应该向用户显示表单以授予应用程序权限,然后重定向回来。这在我的个人电脑上正常工作,但我的朋友遇到了上述问题。

有什么我可以解决的吗?

4

2 回答 2

0

Probably won't fix it but you should separate some of the logic. The part that checks for a logged in Facebook user should be in a Route filter. Then remove the array passed as parameter to the getLoginUrl method (Facebook automatically redirects to the requesting page).

Also your friend might have cookies turned off?

于 2013-06-20T06:15:54.080 回答
0

问题是 Facebook 应用程序处于 Sanbox 模式,因此只有作为应用程序所有者,我才能访问所需的 API。如果其他人提出请求,Facebook 会将他们重定向回来,从而创建一个无限循环。

该问题已通过关闭 Facebook 应用程序设置上的沙盒模式并授予适当的权限来解决。

于 2013-06-24T00:34:09.260 回答