2

我在 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&sdk=php-sdk-3.2.3&scope=email%2Cpublish_stream”,因为它将“X-Frame-Options”设置为'否定'。

4

2 回答 2

2

把它放在bootstrap/start.php里面的某个地方:

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

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

于 2014-05-06T11:06:08.313 回答
0

尝试将您的回调更改为Route::postnot 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.

于 2014-03-03T10:14:11.320 回答