twitter の oauth api

twitter の oauth api
これを使ったら比較的楽だった。

Twitter-OAuth-PHP
https://docs.google.com/View?docID=dcf2dzzs_2339fzbfsf4

リクエストークンの取得。
ログイン遷移。


$to = new TwitterOAuth(CONSUMERKEY, CONSUMERSECRET);
$req_token = $to->getRequestToken();
$request_link = $to->getAuthorizeURL($req_token);
// リクエストークンはログイン後にも必要なので保存
$_SESSION['req_token'] = $req_token;
header("Location: ".$request_link);

ログイン後、アクセストークンの取得。
API呼出。


$req_token = $_SESSION['req_token'];
$oauth_token = $req_token['oauth_token'];
$oauth_token_secret = $req_token['oauth_token_secret'];
$to = new TwitterOAuth(CONSUMERKEY,CONSUMERSECRET,$oauth_token,$oauth_token_secret);
$acc_token = $to->getAccessToken();

$oauth_token = $acc_token['oauth_token'];
$oauth_token_secret = $acc_token['oauth_token_secret'];
$to = new TwitterOAuth(CONSUMERKEY,CONSUMERSECRET,$oauth_token,$oauth_token_secret);
$content = $to->OAuthRequest('https://twitter.com/account/verify_credentials.xml', array(), 'GET');