Skip to content

Instantly share code, notes, and snippets.

@howyi
Last active June 21, 2018 16:40
Show Gist options
  • Save howyi/214d5fc5865a4c4762ab to your computer and use it in GitHub Desktop.
Save howyi/214d5fc5865a4c4762ab to your computer and use it in GitHub Desktop.
Get twitter authorize URL with twitterOAuth
<?php
session_start();
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'hoge');
define('CONSUMER_SECRET','foo');
define('OAUTH_CALLBACK', 'http://localhost');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
print("<a href=\"${url}\">authorize</a>");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment