Selamat menyambut hari kemerdekaan yang ke-64, Malaysia! -CH.

In this article, I will show you how to post status with image to your Twitter account using PHP.
But first, make sure you already have these items with you.
- API Key
- API Secret Key
- Access Token
- Access Token Secret
These items can be generated from your Twitter account developer page.
Step 1
Download codebird from GITHub.
Step 2
Upload codebird to your webserver
Step 3
Create a PHP file using this code. Please take note on the codebird.php file path.
function tweet($message,$image) {
// add the codebird library
require_once('codebird/src/codebird.php');
// note: consumerKey, consumerSecret, accessToken, and accessTokenSecret all come from your twitter app at https://apps.twitter.com/
\Codebird\Codebird::setConsumerKey("API KEY", "API SECRET KEY");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("ACCESS TOKEN", "ACCESS TOKEN SECRET");
//build an array of images to send to twitter
$reply = $cb->media_upload(array(
'media' => $image
));
//upload the file to your twitter account
$mediaID = $reply->media_id_string;
//build the data needed to send to twitter, including the tweet and the image id
$params = array(
'status' => $message,
'media_ids' => $mediaID
);
//post the tweet with codebird
$reply = $cb->statuses_update($params);
}
Step 4
You can post the status and image using this function.
tweet('This is my tweet message','http://www.example.com/image.jpg');
That’s it! Now you can post any tweet with image using PHP. 🙂
Hello
The function works very well.
How can I integrate multipart upload in this function.
I just got this working well… I am assuming all the other functions are listed in the GitHub.