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

Twitter OAuth Error Failed to request resource.

Open cmosboss opened this issue 10 years ago • 2 comments

I have looked at every issue I could find and no one seems to have an answer to how to get twitter OAuth setup. Here is my config file

<?php 
return array( 
     //Storage
    'storage' => 'Session', 
     // Consumers
    'consumers' => array(
    //Twitter
'Twitter' => array(
            'key'         => '*************************',
            'secret'     => '****************************************************',
        ),          
    )
);

This is setup I believe it is correct through #5, #7 and #15. Then I have the following method (obtained from the same issues)

public function loginWithTwitter() 
    {
        $oauth_token = Input::get('oauth_token');
        $oauth_verifier = Input::get('oauth_verifier');
        // get service
        $twit = OAuth::consumer('Twitter');

        // check if code is valid

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

            // This was a callback request from google, get the token
            $token = $twit->requestAccessToken($oauth_token, $oauth_verifier);

            // Send a request with it
            $result = json_decode( $twit->request( 'account/verify_credentials.json' ), true );

            echo print_r($result);

        }
        // if not ask for permission first
        else 
        {
            // get authorization
            $token = $twit->requestRequestToken();
            $url = $twit->getAuthorizationUri(array('oauth_token' => $token->getRequestToken()));

            // return to login url
            return Response::make()->header( 'Location', (string)$url );
        }
    }

This produces the error OAuth \ Common \ Http \ Exception \ TokenResponseException Failed to request resource. This is happening from line

$token = $twit->requestRequestToken();

Is there something else that needs to happen for this to work? a php.ini setting? something in my code? Thanks

cmosboss avatar May 30 '14 18:05 cmosboss

configuration for twitter should look like this:

        'Twitter' => [
            'client_id'     => '***********************************',
            'client_secret' => '*****************************',
            'scope'         => array(),
        ],

artdarek avatar Jun 02 '14 11:06 artdarek

Why isn't this in the readme? Seems silly to have it here in an issue and not upfront. Not very user friendly.

jasper-lyons avatar Jun 04 '15 16:06 jasper-lyons