OAuth using Twitter

続き。。

twitter とつなげてみた。
ただ、twitter にログインしていると
Invalid auth/bad requestってなエラーがでてたので、リクエストークンのところがおかしいのかな?
と思いちょっとエラーハンドリングを追加してみた。
いちおう下記のコードでうまくいった。

※この辺を参考
http://hasin.wordpress.com/2010/04/04/complete-oauth-script-for-twitter-and-linkedin-using-pecl-oauth-extension/



getRequestToken($oauth['twitter']['requesttokenurl']); //get request token
$_SESSION['trequest_token_secret'] = $request_token_info['oauth_token_secret'];
header("Location: {$oauth['twitter']['authurl']}?oauth_token=".$request_token_info['oauth_token']);//forward user to authorize url
}
//get the access token - dont forget to save it
else if(empty($_SESSION['taccess_oauth_token'])) {
$request_token_secret = $_SESSION['trequest_token_secret'];

//@nash error handling when twitter-logged-in user access this page.
//request token is invalid?
try{
$oauthc->setToken($_REQUEST['oauth_token'],$request_token_secret);//user allowed the app, so u
$access_token_info = $oauthc->getAccessToken($oauth['twitter']['accesstokenurl']);
}catch(Exception $e){
unset($_SESSION['trequest_token_secret']);
header('Location: '.htmlspecialchars($_SERVER ['PHP_SELF']));
}
$_SESSION['taccess_oauth_token']= $access_token_info['oauth_token'];
$_SESSION['taccess_oauth_token_secret']= $access_token_info['oauth_token_secret'];
}
//now fetch current users profile which requires authentication
if(isset($_SESSION['taccess_oauth_token'])) {
$access_token = $_SESSION['taccess_oauth_token'];
$access_token_secret =$_SESSION['taccess_oauth_token_secret'];
$oauthc->setToken($access_token,$access_token_secret);
$data = $oauthc->fetch('http://twitter.com/account/verify_credentials.json');
$response_info = $oauthc->getLastResponse();

print_r(json_decode($response_info));

}
?>