I am attempting to use the code below to post a status and an image to twitter. The library is tmhOAuth, the image is coming from a blob in my mysql db as is the mime type and file name.
Basically if an image is found stored in the db row then it sends to twitter using a post to “update_with_media” if no image is found then it just sends the status update alone using “update”. the “update” works fine, but I can’t get the update with media working. I’ve tried several variations from various sites including Twitter’s dev site but no joy. I’d really appreciate another set of eyes oh this.
if(!empty($imgid)) {
$getimg = mysql_query("SELECT filedata, filename, mime_type FROM post_images WHERE id = $imgid");
$img = @mysql_fetch_array($getimg);
$imagedata = $img['filedata'];
$imagename = $img['filename'];
$imagetype = $img['mime_type'];
$theimg = "@{$imagedata};type=$imagetype;filename={$imagename}";
$hasimg = "y";
}
if($hasimg == "y") {
$code = $connection->request( 'POST',
$connection->url('https://upload.twitter.com/1/statuses/update_with_media.json'),
array(
'media[]' => $theimg,
'status' => $thetweet),
true, // use auth
true // multipart
);
} else {
$code = $connection->request('POST',
$connection->url('1.1/statuses/update'),
array('status' => $thetweet));
}
// A response code of 200 is a success
if ($code == 200) {
print "Tweet sent";
} else {
print "Error: $code";