Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to tweet with OAuth in three lines
// Download the latest version of TwitterOAuth from
// Unpack the download and place the twitteroauth.php and OAuth.php files in the same directory as this file.
// Register an application at and from your new apps page get "my access token".
$connection = new TwitterOAuth('app consumer key', 'app consumer secret', 'my access token', 'my access token secret');
$status = $connection->post('statuses/update', array('status' => 'text to be tweeted'));

That does'nt work, but this does


/* If access tokens are not available redirect to connect page. _/
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

$parameters = array('status' => 'put your tweet in here');
$status = $connection->post('statuses/update', $parameters);

// make sure you set your config.php page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment