Laravel 4应用程序在作为facebook应用程序运行时出错

时间:2014-03-03 09:55:59

标签: laravel laravel-4 facebook-sdk-3.0 facebook-sdk-3.1

我在Laravel 4中创建了一个facebook应用程序,问题是它在作为facebook应用程序运行时给出了以下错误

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

但同样的事情在facebook上工作正常。我按照本教程 http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/

以下是我的routes.php

Route::get('home', 'HomeController@showWelcome');
Route::get('/', function() {
$facebook = new Facebook(Config::get('facebook'));
$params = array(
    'redirect_uri' => url('/login/fb/callback'),
    'scope' => 'email,publish_stream',
);
return Redirect::to($facebook->getLoginUrl($params));
}); 

Route::get('login/fb/callback', function() {
$code = Input::get('code');
if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');

$facebook = new Facebook(Config::get('facebook'));
$uid = $facebook->getUser();

if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error');

$me = $facebook->api('/me');

return Redirect::to('home')->with('user', $me);

});

编辑:我已检查过Chrome控制台并收到此错误

拒绝在一个框架中显示'https://www.facebook.com/dialog/oauth?client_id=327652603940310&redirect_ur ... 7736c22f906b948d7eddc6a2ad0&amp; sdk = php-sdk-3.2.3&amp; scope = email%2Cpublish_stream',因为它将'X-Frame-Options'设置为'DENY'。< / p>

2 个答案:

答案 0 :(得分:2)

将它放在 bootstrap / start.php

$app->forgetMiddleware('Illuminate\Http\FrameGuard');

你可以阅读这篇文章: http://forumsarchive.laravel.io/viewtopic.php?pid=65620

答案 1 :(得分:0)

尝试将回调更改为Route::post而不是Route::get。如果我的记忆正确地为我服务,Facebook会发出POST请求,而不是GET请求。

<?php
Route::get('login/fb/callback', function() {
    $code = Input::get('code');

    if (strlen($code) == 0) {
        return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');
    }

    $facebook = new Facebook(Config::get('facebook'));
    $uid = $facebook->getUser();

    if ($uid == 0) {
        return Redirect::to('/')->with('message', 'There was an error');
    }

    $me = $facebook->api('/me');

    return Redirect::to('home')->with('user', $me);

});

查看您发送的链接后,错误实际上会告诉您错误。

REQUEST_URI /
REQUEST_METHOD  POST

加载该页面正在向/发出POST请求,并且如上所述,您需要将索引的路由更改为Route::post