Skip to content

Instantly share code, notes, and snippets.

@taroyabuki
Last active December 14, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taroyabuki/5100756 to your computer and use it in GitHub Desktop.
Save taroyabuki/5100756 to your computer and use it in GitHub Desktop.
<?php
session_start();
$oauth = new OAuth($_SESSION['consumer_key'], $_SESSION['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
if (substr(PHP_OS, 0, 3) == 'WIN') {
$caPath = 'C:/xampp/perl/vendor/lib/Mozilla/CA/';
$caInfo = "${caPath}cacert.pem";
$oauth->setCAPath($caPath, $caInfo);
}
$oauth->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $oauth->getAccessToken('https://api.twitter.com/oauth/access_token?oauth_verifier' . $_GET['oauth_verifier']);
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
//セッションに記録する。データベースなどを使ってもよい。
$_SESSION['access_token'] = $access_token;
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Twitter OAuth End</title>
</head>
<body>
<pre><?php print_r($access_token); ?></pre>
<p>access_tokenをセッションに保存した</p>
<p><a href="twitter-oauth-post.php">送信テスト</a></p>
<p><a href="logout.php">logout</a></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment