I have written the following PHP function (see below) that allows me to tweet either a staus or a status+image.
The status update works fine, but if I pass an image name (and the fact that strlen($image) !=0 dictates a different path through the function), it does not tweet, nor do I get an error.
I have tried manually putting the image path+name into the 'media[]' element of the array, but cannot get this to work.
I have even tried
'media[]' => "http://www.website.com/twitter/images/pic.jpg");
... which is the full path name to the file, as suggested in a previous post. This does actually give me an error:
{"errors":[{"code":189,"message":"Error creating status."}]}
I have followed carefully a few other forum posts, but after a couple of days I am getting a little frustrated? :-).
Any help appreciated.
public function postTweet($tweet, $imagesPath, $image) {
$url = $this->baseTwitterURL . 'statuses/update.json';
$urlMedia = $this->baseTwitterURL . 'statuses/update_with_media.json';
$postURL = "";
$requestMethod = 'POST';
if(strlen($image) == 0) {
$postfields = array(
'status' => $tweet);
$postURL = $url;
}
else {
$imagetoPost = $imagesPath . $image;
$postfields = array(
'status' => $tweet,
'media[]' => "@{$imagetoPost}");
$postURL = $urlMedia;
};
try{
$twitter = new TwitterAPIExchange($this->settings);
$postfields[status] . $this->newline;
echo $twitter->buildOauth($postURL, $requestMethod)
->setPostfields($postfields)
->performRequest();
} catch (Exception $ex) {
echo $ex->getMessage();
}
} // postTweet