Laravel 4应用程序在作为Facebook应用程序运行时出现错误



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

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

但同样的事情在Facebook上运作良好。我遵循了本教程http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/

以下是我的路线.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"设置为"DENY"。

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

$app->forgetMiddleware('IlluminateHttpFrameGuard');

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

尝试将回调更改为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

相关内容

  • 没有找到相关文章

最新更新