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/5100750 to your computer and use it in GitHub Desktop.
Save taroyabuki/5100750 to your computer and use it in GitHub Desktop.
<?php
session_start();
$_SESSION['consumer_key'] = 'Consumer Key';
$_SESSION['consumer_secret'] = 'Consumer Secret';
$callbackUrl = 'http://localhost/twitter/twitter-oauth-end.php';
$oauth = new OAuth($_SESSION['consumer_key'], $_SESSION['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
if (substr(PHP_OS, 0, 3) == 'WIN') {//XAMPP(いいかげん)
$caPath = 'C:/xampp/perl/vendor/lib/Mozilla/CA/';
$caInfo = "${caPath}cacert.pem";
$oauth->setCAPath($caPath, $caInfo);
}//Ubuntuでは自動的に「/etc/ssl/certs/ca-certificates.crt」が読み込まれる
$request_token = $oauth->getRequestToken('https://api.twitter.com/oauth/request_token', $callbackUrl);
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$authUrl = 'https://api.twitter.com/oauth/authorize?oauth_token=' . $_SESSION['oauth_token'];
?>
<!doctype html>
<html>
<head>
<title>Twitter OAuth Start</title>
</head>
<body>
<p><a href="<?php echo $authUrl; ?>">Twitter OAuth Start</a></p>
<p><a href="twitter-oauth-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