Skip to content

Instantly share code, notes, and snippets.

@abraham
Created September 4, 2010 03:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abraham/564882 to your computer and use it in GitHub Desktop.
Save abraham/564882 to your computer and use it in GitHub Desktop.
How to tweet with OAuth in three lines
<?php
// Download the latest version of TwitterOAuth from http://github.com/abraham/twitteroauth/downloads
// Unpack the download and place the twitteroauth.php and OAuth.php files in the same directory as this file.
// Register an application at http://dev.twitter.com/apps and from your new apps page get "my access token".
require_once('twitteroauth.php');
$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'));
@spikeyman00
Copy link

That does'nt work, but this does

session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');

/* 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