artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
684 stars 216 forks source link

TokenResponseException with Twitter Request Token #60

Closed johnregalado closed 10 years ago

johnregalado commented 10 years ago

I'm getting

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

When I try to call twitter. The code dies during the requestRequestToken call

$token = $tw->requestRequestToken(); 

I traced it to this lin Inside of lusitanian/oauth/src/OAuth/OAuth1/Service/AbstractService.php

$responseBody = $this->httpClient->retrieveResponse($this->getRequestTokenEndpoint(), array(), $headers);

my code

        $code = Input::get( 'oauth_token' );
        $oauth_verifier = Input::get( 'oauth_verifier' );
        $tw = OAuth::consumer( 'Twitter' );

        if ( !empty( $code ) ) {
            $token = $tw->getStorage()->retrieveAccessToken('Twitter');
            $tw->requestAccessToken( $code, $oauth_verifier, $token->getRequestTokenSecret() );
            $result = json_decode( $tw->request( 'account/verify_credentials.json') );
            HomeController::codeview($result);
        } else {
            $token = $tw->requestRequestToken();
            $url = $tw->getAuthorizationUri(['oauth_token' => $token->getRequestToken()]);
            return array('authorize' => (string)$url);
        }

Any help would be appreciated, I'm able to use google and facebook just fine. Its twitter that does this.

I also made sure the Allow this application to be used to Sign in with Twitter checkbox was checked inside the settings.

Thanks in advanced.

jrean commented 10 years ago

Hi, Did you specify a callback url? If no, please try.

johnregalado commented 10 years ago

Wow, I feel dumb. I was sending a call back when I was testing it, but it didn't match the call back I setup inside of Twitter Dev. So, I pulled it out of the code because it didn't work either way.

It's working now that my callback URL matches the call back URL that I gave to twitter.

So for anyone else that has this issue, the change to the code above is on the 3rd line.

FROM:

$tw = OAuth::consumer( 'Twitter' );

TO:

$tw = OAuth::consumer( 'Twitter' , 'http://link.to.oauth.callback');

Thanks @jrean for pointing that out. I was so desperate to get this to work that I installed a separate library just for Twitter. I had the same call back issue, but in that library the warning was a little clearer. So when you mentioned the call back here, it all clicked and I got it to work.

Love this Library.