artdarek / oauth-4-laravel

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

Failed to request resource. #84

Open kukuhpro opened 10 years ago

kukuhpro commented 10 years ago

use OAuth\Common\Storage\Session as S;

class AuthController extends BaseController { public function getIndex() { $code = Input::get('oauth_token'); $twitterservice = OAuth::consumer('Twitter'); $storage = new S();

if (!empty($code)) {
  $token = $storage->retrieveAccessToken('Twitter');
  $twitterservice->requestAccessToken(
    Input::get('oauth_token'),
    Input::get('oauth_verifier'),
    $token->getRequestTokenSecret()
  );

  $result = json_decode($twitterservice->request('account/verify_credentials'));

  echo 'result: <pre>' . print_r($result, true) . '</pre>';
}

i always get error 'Failed to request resource'

help me please..

i3zhe commented 10 years ago

Just follow the example in the README, this one works for me: Since you're using Input::get('oauth_token') and Input::get('oauth_verifier'), I don't understand why you try to use the session access token too?

$token = Input::get( 'oauth_token' );
$verify = Input::get( 'oauth_verifier' );

// get twitter service
$tw = OAuth::consumer( 'Twitter' );

if ( !empty( $token ) && !empty( $verify ) ) {

        // This was a callback request from twitter, get the token
        $token = $tw->requestAccessToken( $token, $verify );

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

        var_dump($result);
}
kukuhpro commented 10 years ago

Thanks for your concern... I'm sorry i thought it must used session access token... But if you say that.. I will fix it.

Thank you On Jul 26, 2014 9:37 PM, "i3zhe" notifications@github.com wrote:

Just follow the example in the README, this one works for me: Since you're using Input::get('oauth_token') and Input::get('oauth_verifier'), I don't understand why you try to use the session access token too?

$token = Input::get( 'oauth_token' );$verify = Input::get( 'oauth_verifier' ); // get twitter service$tw = OAuth::consumer( 'Twitter' ); if ( !empty( $token ) && !empty( $verify ) ) {

    // This was a callback request from twitter, get the token
    $token = $tw->requestAccessToken( $token, $verify );

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

    var_dump($result);}

— Reply to this email directly or view it on GitHub https://github.com/artdarek/oauth-4-laravel/issues/84#issuecomment-50235779 .

i3zhe commented 10 years ago

Sorry, I might be wrong. The session token should be an option, not required.