Hi.I use the PHP SDK by j7mbo to update status with images.
First I send some images to the https://upload.twitter.com/1.1/media/upload.json and get seems to be normal response. I take each id to the array $ids and put them separated by comma to the array $parameters:
$parameters['media_ids'] = implode(',', $ids);
So, all array is:
array('status' => 'TEXT OF STATUS', 'media_ids' => '2423423423434234,34343434343434');
After sending the request to the https://api.twitter.com/1.1/statuses/update.json I get request like I never added images ids (have no extended_entities).
The fulll code looks like:
$twitter = new TwitterAPIExchange($settings);
$images = array('/path/to/pic1', '/path/to/pic2');
if(!empty($images)){
$url = 'https://upload.twitter.com/1.1/media/upload.json';$method='POST';
foreach($images as $img){
if(!is_file($img))
continue;
$file2upload = array('media' => "@$img");
$action = $twitter->buildOauth($url, $method)->setPostfields($file2upload)->performRequest();
$return['images'][] = $answer = json_decode($action);
if(!is_null($answer) and !isset($answer->error)){
$ids[] = $answer->media_id_string;
}
}
}
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$parameters = array(
'status' => $text,
);
switch(count($ids)){
case 0:
break;
case 1:
$parameters['trim_user'] = 1;$parameters['media_ids'] = $ids[0];break;
default:
$parameters['trim_user'] = 1;$parameters['media_ids'] = implode(',', $ids);break;
}
$tweetObj = new TwitterAPIExchange($settings);
$response = $tweetObj->buildOauth($url, $method)->setPostfields($parameters)->performRequest();
$return['tweet'] = json_decode($response);
$return['parameters'] = $tweetObj->getPostfields();
In the $return I have responses of each image uploading then resonse of the status updating. After that becomes the postfields that I send with new tweet.
Here the full return:
array(3) {
["images"]=>
array(2) {
[0]=>
object(stdClass)#18 (4) {
["media_id"]=>
int(527777203019579392)
["media_id_string"]=>
string(18) "527777203019579392"
["size"]=>
int(59725)
["image"]=>
object(stdClass)#19 (3) {
["w"]=>
int(769)
["h"]=>
int(520)
["image_type"]=>
string(9) "image/png"
}
}
[1]=>
object(stdClass)#20 (4) {
["media_id"]=>
int(527777211227860992)
["media_id_string"]=>
string(18) "527777211227860992"
["size"]=>
int(111948)
["image"]=>
object(stdClass)#21 (3) {
["w"]=>
int(500)
["h"]=>
int(375)
["image_type"]=>
string(10) "image/jpeg"
}
}
}
["tweet"]=>
object(stdClass)#23 (22) {
["created_at"]=>
string(30) "Thu Oct 30 11:01:08 +0000 2014"
["id"]=>
int(527777215615107072)
["id_str"]=>
string(18) "527777215615107072"
["text"]=>
string(21) "SomeNewTest1414666864"
["source"]=>
string(56) "Style i"
["truncated"]=>
bool(false)
["in_reply_to_status_id"]=>
NULL
["in_reply_to_status_id_str"]=>
NULL
["in_reply_to_user_id"]=>
NULL
["in_reply_to_user_id_str"]=>
NULL
["in_reply_to_screen_name"]=>
NULL
["user"]=>
object(stdClass)#24 (40) {
["id"]=>
int(2837937831)
["id_str"]=>
string(10) "2837937831"
["name"]=>
string(7) "Style i"
["screen_name"]=>
string(9) "Styleiapp"
["location"]=>
string(0) ""
["profile_location"]=>
NULL
["description"]=>
string(0) ""
["url"]=>
NULL
["entities"]=>
object(stdClass)#25 (1) {
["description"]=>
object(stdClass)#26 (1) {
["urls"]=>
array(0) {
}
}
}
["protected"]=>
bool(false)
["followers_count"]=>
int(0)
["friends_count"]=>
int(0)
["listed_count"]=>
int(0)
["created_at"]=>
string(30) "Mon Oct 20 09:30:59 +0000 2014"
["favourites_count"]=>
int(0)
["utc_offset"]=>
NULL
["time_zone"]=>
NULL
["geo_enabled"]=>
bool(false)
["verified"]=>
bool(false)
["statuses_count"]=>
int(81)
["lang"]=>
string(2) "ru"
["contributors_enabled"]=>
bool(false)
["is_translator"]=>
bool(false)
["is_translation_enabled"]=>
bool(false)
["profile_background_color"]=>
string(6) "C0DEED"
["profile_background_image_url"]=>
string(48) "http://abs.twimg.com/images/themes/theme1/bg.png"
["profile_background_image_url_https"]=>
string(49) "https://abs.twimg.com/images/themes/theme1/bg.png"
["profile_background_tile"]=>
bool(false)
["profile_image_url"]=>
string(79) "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png"
["profile_image_url_https"]=>
string(80) "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png"
["profile_link_color"]=>
string(6) "0084B4"
["profile_sidebar_border_color"]=>
string(6) "C0DEED"
["profile_sidebar_fill_color"]=>
string(6) "DDEEF6"
["profile_text_color"]=>
string(6) "333333"
["profile_use_background_image"]=>
bool(true)
["default_profile"]=>
bool(true)
["default_profile_image"]=>
bool(true)
["following"]=>
bool(false)
["follow_request_sent"]=>
bool(false)
["notifications"]=>
bool(false)
}
["geo"]=>
NULL
["coordinates"]=>
NULL
["place"]=>
NULL
["contributors"]=>
NULL
["retweet_count"]=>
int(0)
["favorite_count"]=>
int(0)
["entities"]=>
object(stdClass)#27 (4) {
["hashtags"]=>
array(0) {
}
["symbols"]=>
array(0) {
}
["user_mentions"]=>
array(0) {
}
["urls"]=>
array(0) {
}
}
["favorited"]=>
bool(false)
["retweeted"]=>
bool(false)
["lang"]=>
string(2) "en"
}
["parameters"]=>
array(3) {
["status"]=>
string(21) "SomeNewTest1414666864"
["trim_user"]=>
string(1) "1"
["media_ids"]=>
string(37) "527777203019579392,527777211227860992"
}
}
Sorry for my English and Thank You