Skip to content

@abraham /twitter.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

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
Something went wrong with that request. Please try again.