Twitter OAUTH returns an empty array
oauth, php, twitter, twitter-oauth
Solution
Are you passing the "oauth_verifier" to the getAccessToken method? In the sample code you are giving, you are not doing it. Take a look at this diagram, specially on part D
I have used twitteroauth in the past and I remember doing it like this. (starting second fase)
$twitterOauth = new TwitterOAuth($AppId, $twSecret, $_COOKIE['oauth_token'], $_COOKIE['oauth_token_secret']);
$twToken = $twitterOauth->getAccessToken($_REQUEST['oauth_verifier']);
$newTwitterOauth = new TwitterOAuth($AppId, $twSecret, $twToken['oauth_token'], $twToken['oauth_token_secret']);
$response = (array) $newTwitterOauth->get('account/verify_credentials');
var_dump($response);
There are a couple of suggestions I would do though:
- Instead of stoing that information in a cookie, I strongly suggest you use sessions to do the job.
- If you insist on using cookies, please use the setcookie function.
Problem
I am working on twitter authentication, everything seems to work well till i get to `getAccessToken` which returns `Array ( [ ] => )`. What I have done: First phase: ``` $connection = new TwitterOAuth('xxxxxxxx','xxxxxxxx'); $temporary_credentials = $connection->getRequestToken('http://example.com/profile.php?passurl=1'); $redirect_url = $connection->getAuthorizeURL($temporary_credentials); $_COOKIE['oauth_token'] = $temporary_credentials['oauth_token']; $_COOKIE['oauth_token_secret'] = $temporary_credentials['oauth_token_secret']; header("Location: $redirect_url"); ``` second phase (this is where i encounter the problem) ``` $connection = new TwitterOAuth( 'xxxxxxxxxx', 'xxxxxxxxxx', $_COOKIE['oauth_token'], $_COOKIE['oauth_token_secret'] ); $token_credentials = $connection->getAccessToken(); ``` I intend saving the `$token_credentials` values in the database but it returns an empty array: `Array ( [ ] => )` What am i not getting right?