oauth-4-laravel
oauth-4-laravel copied to clipboard
TokenResponseException with Twitter Request Token
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 config:
return array(
/*
|--------------------------------------------------------------------------
| oAuth Config
|--------------------------------------------------------------------------
*/
/**
* Storage
*/
'storage' => 'Session',
/**
* Consumers
*/
'consumers' => array(
/**
* Facebook
*/
'Facebook' => array(
'client_id' => '123',
'client_secret' => '123123123123',
'scope' => array('email'),
),
/**
* Twitter
*/
'Twitter' => array(
'client_id' => 'asd',
'client_secret' => 'asdadsdadssad',
),
)
i test with call back but not work.
my code:
public function twitter() { // get data from input $token = Input::get( 'oauth_token' ); $verify = Input::get( 'oauth_verifier' );
// get twitter service
$tw = OAuth::consumer('Twitter', URL::to('auth/provider/twitter'));
// check if code is valid
// if code is provided get user data and sign in
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 );
$message = 'Your unique Twitter 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 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 );
}
}
Any help would be appreciated, I'm able to use facebook just fine. Its twitter that does this.
Thanks
try this... public function loginWithTwitter() {
// get data from input
$token = Input::get('oauth_token');
$verify = Input::get('oauth_verifier');
// get twitter service
$tw = OAuth::consumer('Twitter', 'http://localhost:8000/oauth/twitter');
// check if code is valid
// if code is provided get user data and sign in
if (!empty($token) && !empty($verify)) {
try {
if (!isset($_SESSION['token'])) {
// This was a callback request from twitter, get the token
$token = $tw -> requestAccessToken($token, $verify);
$_SESSION['token'] = $token -> getAccessToken();
}
} catch(Exception $e) {
return Redirect::to('oauth/user');
}
// Send a request with it
$result = json_decode($tw -> request('account/verify_credentials.json'), true);
$message = 'Your unique Twitter user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message . "<br/>";
// SocialData::storeTwitterData($result);
//Var_dump
//display whole array().
var_dump($result);
// echo "<a href='logout'>Logout</a>";
}
// if not ask for permission first
else {
// 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);
}
}
check this code but not work. error: OAuth \ Common \ Http \ Exception \ TokenResponseException Failed to request resource.
Same problem here. Anyone knows why?
Same here, did you manage to make it work?
same with me, tried another bitbucket oauth1, it's working fine, twitter on anyone !?
I realized that it wasn't token problem, but silly try to post same status twice. Though exception that is thrown is not very clear.
i have the same problem... :( how fix it.... facebook works fine..... :+1:
I have the same problem :(