Created
September 4, 2010 03:40
-
-
Save abraham/564882 to your computer and use it in GitHub Desktop.
How to tweet with OAuth in three lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. _/$_SESSION['access_token']['oauth_token']) || empty($ SESSION['access_token']['oauth_token_secret'])) {
if (empty($_SESSION['access_token']) || empty(
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