Cannot get OAuth access token using the Twitter API
I'm creating a web app that will use Twitter API's and OAuth so that my app can post to my users twitter accounts.
Here is where I'm at so far - I get to the twitter authorization page.
Authorize the app to be able to post to my twitter account, which sends me to my callback file.
Get the oath_token and oauth_verifier info.
That's where I'm stuck. I CAN NOT seem to get the access token. Here is my callback code:
include 'db.php';
include 'EpiCurl.php';
include 'EpiOAuth.php';
include 'EpiTwitter.php';
include 'secret.php';
$Twitter = new EpiTwitter($consumerKey, $consumerSecret);
// user comes from twitter
$Twitter->setToken($_GET['oauth_token']);
$token = $Twitter->getAccessToken();
setcookie('oauth_token', $token->oauth_token);
setcookie('oauth_token_secret', $token->oauth_token_secret);
$Twitter->setToken($token->oauth_token, $token->oauth_token_secret);
I've been researching and testing for about 5 hours and still nothing. I have tried to echo $token and it just comes out empty.
Am I missing something big here? seems like 开发者_StackOverflowan easy task..? Thank you so much for any help :))))
Try this:
$Twitter = new EpiTwitter($consumerKey, $consumerSecret);
// user comes from twitter
$Twitter->setToken($_GET['oauth_token']);
$oauth_verifier = $_GET['oauth_verifier'];
$token = $Twitter->getAccessToken(array('oauth_verifier' => $oauth_verifier));
$Twitter->setToken($token->oauth_token, $token->oauth_token_secret);
$creds = $Twitter->get('/account/verify_credentials.json');
Hope it helps.
精彩评论