Hey,
I am using the twitter api by j7mbo ( http://github.com/j7mbo/twitter-api-php ) because I am making a small personal wordpress site, and just wanted everything minimal and in my experience with namespaces etc. wordpress doesnt really like playing with them
ANYWAY, I upload an image to https://upload.twitter.com/1.1/media/upload.json and it returns fine, with a media object. However when i try update a new statusm with the media ids attached, the tweet never displays an image?
heres some sample code
$img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'large'); // get the image object of what I want to upload
if($img)
{
$url = 'https://upload.twitter.com/1.1/media/upload.json';
$requestMethod = 'POST';
$postfields = array(
'media' => file_get_contents($img[0])
);
$twitter = new TwitterAPIExchange($settings);
$result = $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest(true);
$json = json_decode($result);
}
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$postfields = array(
'status' => titleSend($post->post_title,$post->ID)
);
if($json) // if there is json from the media upload add it as another parameter
{
$postfields['media_ids'] = $json->media_id_string;
}
$twitter = new TwitterAPIExchange($settings);
$results = $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
Any help on the subject would be greatly appreciated,
Do the media ids have to be formatted in a specific way? (anything to do with the fact it can have up to 4 media entities?)
Thanks
Jonny