"media parameter is invalid" when updating status with multiple JPEGs


I’m trying to upload a JPEG using Twitter4J.uploadMedia(). Here are the images 1 2 3 4

They seem to be uploaded successfully (I guess). But it failed when updating status. Here’s the error message:

twitter4j.TwitterException: 400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.
twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - media parameter is invalid.
code - 44

        at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:163) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
        at twitter4j.HttpClientBase.request(HttpClientBase.java:53) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
        at twitter4j.HttpClientBase.post(HttpClientBase.java:82) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
        at twitter4j.TwitterImpl.post(TwitterImpl.java:1598) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
        at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:213) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]

Maybe there’s something wrong with those images. I have posted successfully multiple times, and some of the time, it fails.

I wonder if anyone can help me with this issue. Thank you!


Are you able to post some of your code (excluding the consumer key and secret)?

Do the requests to media/upload return media_ids?


I use Twitter4J. Here’s the important part of the code.

        val status = new StatusUpdate(s"some text http://www.someurl.com")
        val mediaIds = data.imageUrls.map { imgUrl =>

I have confirmed that mediaIds look correct. So, I guess the uploading part is successful.

The error occurs on updateStatus(…)


The media_ids parameter for POST statuses/update takes a comma-separated list, so probably mediaIds.toArray is wrong.

That said, I’m not sure how to get a comma-separated list from the mediaIds variable, nor would I know what format is expected by Twitter4J’s status.setMediaIds method.


setMediaIds(…) is a Twitter4J method that accepts an array.

It should be ok because there are many times that it updates statuses successfully with images. However, it seems to fail like 30% of the time.


Ok, this is dumb. I was uploading more than 4 images. That’s why “media parameter is invalid” occurs.


Thanks for telling us, @tanin.


If you get back a "media parameter is invalid code 44 " when you try to post a status update after a successful upload, it might also mean that the media format was wrong. Previously I had issues where I recorded in 1920x1088 and the largest allowable resolution was 1280x720 according to: https://dev.twitter.com/rest/public/uploading-media. For sanity testing I tried it with twurl and it also failed until I recorded the videos in an allowed resolution.

Strangely these videos can be uploaded on the twitter website itself - must be a different method…