How to tweet an image using PHP from my website?
php, twitter
Solution
You need to supply Twitter the fully qualified URI to your image.
You have the following code:
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
Unfortunately, that's not a complete URL to an image, it's a relative URL. Instead, you need to provide something along the lines of this:
$params = array(
'status' => $comments,
'media[]' => "http://www.example.com/images/image1.jpg"
);
In addition, according to the Twitter API v1 documentation, you need to use `statuses/update_with_media` instead of `statuses/update`.
If you are using Twitter API v1, Twitter also recommends using v1.1 instead.
Problem
I am trying to tweet an image using php. I have read the documentation and followed a some tutorials. I don't have any problem when sending a message; however, it does not work with images. I can not find where my mistake is, can anyone help?? I would deeply appreciate it. ``` <?php $comments = $_POST['comment']; if (isset($_POST['Twitter'])) { require_once('twitter/codebird-php/src/codebird.php'); \Codebird\Codebird::setConsumerKey("xxxxxx","xxxxxx"); $cb = \Codebird\Codebird::getInstance(); $cb->setToken("xxxxxx", "xxxxxxxxxx"); $params = array( 'status' => $comments, 'media[]' => "/images/image1.jpg" ); $reply = $cb->statuses_update($params); echo "You have posted your message succesfully"; } else{ echo "You havent posted anythingh"; } ?> ```