Facebook TokenResponseException with Laravel 4.1 and oauth-4-laravel

I get a TokenResponseException from Laravel when I try to access my website using Facebook oauth-4-laravel .

OAuth \ Common \ Http \ Exception \ TokenResponseException
Failed to request resource.

Using the Facebook JavaScript API works as intended, so I'm sure my app is set up correctly.

Are there any known issues that may cause this issue? Am I doing something wrong, or is this a bug in the library?

With the exception of the redirect line that runs around another error , my code is identical to the code example on the GitHub page. I think an exception is thrown when I try to get a token from a Facebook service object.

Here is the code:

public function loginWithFacebook() {
    // get data from input
    $code = Input::get( 'code' );

    // get fb service
    $fb = OAuth::consumer( 'Facebook' );

    // check if code is valid

    // if code is provided get user data and sign in
    if ( !empty( $code ) ) {
        // This was a callback request from google, get the token
        $token = $fb->requestAccessToken( $code );

        // Send a request with it
        $result = json_decode( $fb->request( '/me' ), true );

        $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        echo $message. "<br/>";

        //Var_dump
        //display whole array().
        dd($result);

    }
    // if not ask for permission first
    else {
        // get fb authorization
        $url = $fb->getAuthorizationUri();

        // return to facebook login url
        // ref: https://github.com/artdarek/oauth-4-laravel/issues/27
        //return Response::make()->header( 'Location', (string)$url );
        return Redirect::to((string)$url);
    }

}

And screenshot :

screenshot

Thank.

+3
6

. , , return_uri , . , , , .

$fb = OAuth::consumer('Facebook','http://url.to.redirect.to/');

$fb = OAuth::consumer('Facebook','http://url.to.redirect.to');
+1

_get_contents ( " https://www.facebook.com" );

allow_url_fopen = 0 php.ini, , allow_url_fopen = 1

+1

, google, facebook, maby fb

public function loginWithFacebook() {

    // get data from input
    $code = Input::get( 'code' );

    // get fb service
    $fb = OAuth::consumer( 'Facebook' );



    // check if code is valid

    // if code is provided get user data and sign in
    if ( !empty( $code ) ) {

        // This was a callback request from facebook, get the token
        $token = $fb->requestAccessToken( $code );

        // Send a request with it
        $result = json_decode( $fb->request( '/me' ), true );

        $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        echo $message. "<br/>";

        //Var_dump
        //display whole array().
        dd($result);

    }
    // if not ask for permission first
    else {


        // get fb authorization
        $url = $fb->getAuthorizationUri();

        // return to facebook login url
        return Redirect::to( (string)$url );            
    }

}
0

.. ..

-

, . error_reporting, , . file_get_contents 401 Unauthorized, .

auth- URL- , .

0

$token = $fb->requestAccessToken( $code );

var_dump, .

object(OAuth\OAuth2\Token\StdOAuth2Token)[279]
protected 'accessToken' => string 'your-accessToken' (length=180)
protected 'refreshToken' => null
protected 'endOfLife' => int 1404625939
protected 'extraParams' => 
     array (size=0)
  empty

, accessToken. , loginWithFacebook .

0

I had the same problem. I tried to access facebook schedule. The point is not that he could not access the URL, namely that Facebook returned a 400 error, because I did not miss the parameters. Try connecting to HTTPS on the site where the HTTPS connection will work. For instance. Try the following:

file_get_contents("https://www.namhost.com");

If this works, you should understand why the HTTPs connection you are connecting to fails because the problem is not that you cannot connect to the HTTP addresses, but rather that what you are connecting to don't like the request.

0
source

All Articles