2

I am creating a facebook application in Laravel 4, the problem is it is giving me following error while running as a facebook application

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

but the same thing is working fine out of facebook.I followed this tutorial http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/

Following is my 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);

});

Edit: I have checked chrome console and getting this error

Refused to display 'https://www.facebook.com/dialog/oauth?client_id=327652603940310&redirect_ur…7736c22f906b948d7eddc6a2ad0&sdk=php-sdk-3.2.3&scope=email%2Cpublish_stream' in a frame because it set 'X-Frame-Options' to 'DENY'.

Devendra Verma
  • 938
  • 1
  • 13
  • 29
  • `Route::get('login/fb/callback', function() {` should be `Route::get('/login/fb/callback', function() {` I think – We0 Mar 03 '14 at 10:05
  • The error is that the controller isn't being found, so when on local it works fine as domain.com/ + "login/fb/callback" works, but when on Facebook it needs the "/" in front – We0 Mar 03 '14 at 10:06
  • @We0 still getting the same error. – Devendra Verma Mar 03 '14 at 10:10
  • The slash has nothing to do with it. Laravel is smart enough to know that. – ollieread Mar 03 '14 at 10:12
  • @DevendraVerma I just finished building the exact same thing and also looked at that guide, didn't work for me, so I used this: http://hybridauth.sourceforge.net/userguide/IDProvider_info_Facebook.html – We0 Mar 03 '14 at 10:14

2 Answers2

2

Put this somewhere inside bootstrap/start.php:

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

You can read this post: http://forumsarchive.laravel.io/viewtopic.php?pid=65620

0

Try changing your callback to be Route::post not Route::get. If my memory serves me correctly, Facebook places a POST request, not a GET request.

<?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);

});

After looking at the link that you sent, the error actually tells you what is wrong.

REQUEST_URI /
REQUEST_METHOD  POST

Loading that page is making a POST request to /, and like I suggested above, you'll need to change the route for the index to Route::post.

ollieread
  • 6,018
  • 1
  • 20
  • 36