Two steps:
Step one:
String MEDIA_UPLOAD = "https://upload.twitter.com/1.1/media/upload.json"
params:
“media” -> URL [http://www.rightmove.co.uk/news/wp-content/uploads/2016/05/know-the-rules-happy-296x197.jpg]
Map response = restTemplate.postForObject(MEDIA_UPLOAD, postParams, Map.class);
//Get media id here:
String mediaID = response.get(“media_id_string”);
Step two:
String STATUSES_UPDATE = “https://api.twitter.com/1.1/statuses/update.json”;
postParameters:
“status” -> “message”
“media_ids” -> mediaID
String id = restTemplate.postForObject(STATUSES_UPDATE, postParameters, Tweet.class);
For failure:
“I/O error on POST request for … Server returned HTTP response code: 403 for URL”, it failed at first step.
For failure:
“Error consuming Twitter REST API” and “Something is broken at Twitter. Please see http://dev.twitter.com/pages/support”, it failed at the second step. (Which means I can get a media id from the first step, and it shows successful in uploading)