oauth-4-laravel icon indicating copy to clipboard operation
oauth-4-laravel copied to clipboard

requestAccessToken() errors: "Failed to request resource."

Open simplenotezy opened this issue 9 years ago • 11 comments

When running:

        /**
         * Get Facebook sDK
         */

            $fb = OAuth::consumer( 'Facebook' );

        /**
         * Set code
         */

            $fb->requestAccessToken($facebook_token); // this line

I'll get the error:

"Failed to request resource."

image

Why?

simplenotezy avatar Oct 14 '14 15:10 simplenotezy

I get the same error when using $googleService->requestAccessToken( $code );

For some reason, in Lusitanian it gets 'false' back from google.

GregersBoye avatar Oct 14 '14 22:10 GregersBoye

I didn't any problems with facebook, it works well for me, but not with twitter.

    // get request token
    $reqToken = $tw->requestRequestToken();

    // get Authorization Uri sending the request token
    $url = $tw->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));

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

It get requestAccessToken() errors: "Failed to request resource." when call requestRequestToken();

when I manually use curl to request token, it returned the access token and directly input to this methods:

$url = $tw->getAuthorizationUri(array('oauth_token' => 'manually input access token'));

and it works returned PIN.

so twitter authentication process working, but not with method requestRequestToken(), anyone !?

oizawa avatar Nov 14 '14 03:11 oizawa

I am still experincing this issue. Anyone would know why?

simplenotezy avatar Dec 11 '14 12:12 simplenotezy

Try to pass the OAuth redirect URIs manually - facebook goes all willy-nilly about missing trailing slashes.

RaniSharim avatar Dec 11 '14 13:12 RaniSharim

What do you mean Rani?

After debugging, this is the request that fails:

https://graph.facebook.com/oauth/access_token

simplenotezy avatar Dec 11 '14 13:12 simplenotezy

$fb = OAuth::consumer( 'Facebook','http://my.app.com/' ); Instead of $fb = OAuth::consumer( 'Facebook');

This will send the redirect URI with trailing a slash, which doesn't always happen automatically, and which facebook insists on.

RaniSharim avatar Dec 11 '14 13:12 RaniSharim

Ah, I see. I've tried. Still, without luck.

Anyways, shouldn't facebook return a error message if this was the issue?

simplenotezy avatar Dec 11 '14 13:12 simplenotezy

It does, and returns it in the body, but the inner function doesn't read it.

You have to make a change to lusitanian\oauth\src\OAuth\Common\Http\Client\StreamClient.php, at about line 50, to make it make a request with "ignore errors" on, and read the response body.

Take a look at this stackexchange thread: http://stackoverflow.com/questions/3710147/php-get-content-of-http-400-response

RaniSharim avatar Dec 11 '14 13:12 RaniSharim

Thanks Rani, I've tried implementing that, but it does not work.

Fun thing is, query takes 22 seconds before it fails (tried extending timeout period, no affect, still around 22seconds).

My staging server works perfectly - strange - maybe some Facebook domain configuration that is not correct, but since I don't get any error responses as to why request fails (!!), I have no idea where to start.

simplenotezy avatar Dec 11 '14 13:12 simplenotezy

That is odd. Maybe you should try inspecting $http_response_header - at least you'll which status code is returned, if any.

RaniSharim avatar Dec 11 '14 13:12 RaniSharim

Same problem, i'm the developer of the app and with my fb account all works fine, but with other users and with "/me/taggable_friends" does not work :S

cmarfil avatar Jan 13 '15 14:01 cmarfil