Skip to content

Instantly share code, notes, and snippets.

@WillJW
Created September 5, 2014 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillJW/5a6090a2e0b26afd93ce to your computer and use it in GitHub Desktop.
Save WillJW/5a6090a2e0b26afd93ce to your computer and use it in GitHub Desktop.
Upload photo to Twitter
<?php
require '3rdparty/tmhOAuth/tmhOAuth.php';
$connection = new tmhOAuth(array(
'consumer_key' => TWITTER_API_KEY,
'consumer_secret' => TWITTER_API_SECRET,
'user_token' => TWITTER_ACCESS_TOKEN,
'user_secret' => TWITTER_ACCESS_TOKEN_SECRET
));
$image = '/path/to/image.png';
$code = $connection->request(
'POST',
'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => '@' . $image,
'status' => 'Tweet content'
),
true,
true
);
if ($code !== 200) {
throw new Exception('Error uploading photo');
}
$response = json_decode($connection->response['response']);
$url = $response->entities->media[0]->display_url;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment