No images in post


#1

Hey,

I need help for posting my articles in a tweet. It only posts a status without a image.
Can someone help me? I have a media_id but it will not accepted.

Öznur


#2

Can you provide an example of the code you’ve tried here?


#3

Here is my code.

/* Upload image */
<          $file = file_get_contents($temp);
                    $data = base64_encode($file);
                    $url    = 'https://upload.twitter.com/1.1/media/upload.json';
                    $method = 'POST';
                    $params = array(
                        'media_data' => $data
                    );

                    $twitter = new TwitterAPIExchange($settings);
                    $data     = $twitter->request($url, $method, $params);

                    /** Store the media id for later **/
                    $data = @json_decode($data, true);

                    $mediaId = $data['media_id'];

                    /* Create tweet and reference image */
                    $url    = 'https://api.twitter.com/1.1/statuses/update.json';
                    $method = 'POST';
                    $params = [
                        'status' => $status,
                        'possibly_sensitive' => false,
                        'media_ids' => $mediaId
                    ];
                    $data     = $twitter->request($url, $method, $params);

                    $data = @json_decode($data, true);
>

#4

at what point are getting a valid mediaId value?


#5

at this point


#6

Can you help me?


#7

Not really. The only possible idea I have right now is that you’re using media_id not media_id_str which is what we recommend but that shouldn’t matter if you’re not using JavaScript. What’s the response from the post to statuses/update?


#8
array(23) { ["created_at"]=> string(30) "Wed Feb 20 09:02:55 +0000 2019" ["id"]=> int(1098145965670912000) ["id_str"]=> string(19) "1098145965670912000" ["text"]=> string(6) "Rieker" ["truncated"]=> bool(false) ["entities"]=> array(4) { ["hashtags"]=> array(0) { } ["symbols"]=> array(0) { } ["user_mentions"]=> array(0) { } ["urls"]=> array(0) { } } ["source"]=> string(74) "Schuhfachmann.de" ["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"]=> array(42) { ["id"]=> int(272901659) ["id_str"]=> string(9) "272901659" ["name"]=> string(16) "Schuhfachmann.de" ["screen_name"]=> string(13) "schuhfachmann" ["location"]=> string(5) "Gotha" ["description"]=> string(166) "https://t.co/zODg2HBZkX ist Ihr zuverlässiger Modepartner für den unkomplizierten Schuh- und Accessoires-Einkauf im Internet. Impressum: https://t.co/WE1lrq1YOS" ["url"]=> string(22) "http://t.co/5bER2wLsrp" ["entities"]=> array(2) { ["url"]=> array(1) { ["urls"]=> array(1) { [0]=> array(4) { ["url"]=> string(22) "http://t.co/5bER2wLsrp" ["expanded_url"]=> string(27) "http://www.schuhfachmann.de" ["display_url"]=> string(16) "schuhfachmann.de" ["indices"]=> array(2) { [0]=> int(0) [1]=> int(22) } } } } ["description"]=> array(1) { ["urls"]=> array(2) { [0]=> array(4) { ["url"]=> string(23) "https://t.co/zODg2HBZkX" ["expanded_url"]=> string(23) "http://Schuhfachmann.de" ["display_url"]=> string(16) "Schuhfachmann.de" ["indices"]=> array(2) { [0]=> int(0) [1]=> int(23) } } [1]=> array(4) { ["url"]=> string(23) "https://t.co/WE1lrq1YOS" ["expanded_url"]=> string(27) "http://tinyurl.com/yc4sq5ow" ["display_url"]=> string(20) "tinyurl.com/yc4sq5ow" ["indices"]=> array(2) { [0]=> int(141) [1]=> int(164) } } } } } ["protected"]=> bool(false) ["followers_count"]=> int(720) ["friends_count"]=> int(1794) ["listed_count"]=> int(26) ["created_at"]=> string(30) "Sun Mar 27 12:05:53 +0000 2011" ["favourites_count"]=> int(0) ["utc_offset"]=> NULL ["time_zone"]=> NULL ["geo_enabled"]=> bool(false) ["verified"]=> bool(false) ["statuses_count"]=> int(10253) ["lang"]=> string(2) "de" ["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(84) "http://pbs.twimg.com/profile_images/1290282823/schuhfachmann_1600x1600neu_normal.jpg" ["profile_image_url_https"]=> string(85) "https://pbs.twimg.com/profile_images/1290282823/schuhfachmann_1600x1600neu_normal.jpg" ["profile_banner_url"]=> string(58) "https://pbs.twimg.com/profile_banners/272901659/1431091458" ["profile_link_color"]=> string(6) "1DA1F2" ["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) ["has_extended_profile"]=> bool(false) ["default_profile"]=> bool(true) ["default_profile_image"]=> bool(false) ["following"]=> bool(false) ["follow_request_sent"]=> bool(false) ["notifications"]=> bool(false) ["translator_type"]=> string(4) "none" } ["geo"]=> NULL ["coordinates"]=> NULL ["place"]=> NULL ["contributors"]=> NULL ["is_quote_status"]=> bool(false) ["retweet_count"]=> int(0) ["favorite_count"]=> int(0) ["favorited"]=> bool(false) ["retweeted"]=> bool(false) ["lang"]=> string(2) "nl" }

#9

Do you have an idea?


#10

I’m not a regular PHP coder so not really. @abraham I would not usually tag individuals so apologies in advance, any thoughts on this? It sounds weird for sure.