"The validation of media ids failed." Error Code 324


#1

I have been able to successfully post status updates with images attached. I am using C#/.NET with a REST framework called Hammock. First, I upload the images to upload.twitter.com/1.1/media/upload.json and get media_ids back. Then, I make a request to api.twitter.com/1.1/statuses/update.json with the media_ids parameter. This works fine except that occassionally, with larger images, Twitter responds to my status update request with the following JSON:
{“errors”:[{“code”:324,“message”:“The validation of media ids failed.”}]}
I have tried waiting several minutes between the time of media upload and status update with no success. It would be nice if Twitter would put 324 on their list of error codes here: https://dev.twitter.com/overview/api/response-codes
It would also be a solid idea to not respond with an HTTP 200 as well as a media_id if the image is too large. I have since baked in additional logic to do a lookup to /help/configuration.json to determine the max image size. I no longer allow images larger than that to be attached to Tweets in my application, and the problem is going away. However, I still believe this particular error response should be documented properly.

Here are the exact (except for sensitive values being xxxx’d out) requests/responses seen in Fiddler:

Media Upload Request
POST https://upload.twitter.com/1.1/media/upload.json HTTP/1.1
Authorization: OAuth oauth_consumer_key=“xxxxxxxxxxx”,oauth_nonce=“xxxxxxxxxxx”,oauth_signature=“xxxxxxxxx”,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=“1418763417”,oauth_token=“xxxxxxxxxx”,oauth_version="1.0a"
Content-Type: multipart/form-data; boundary=5fb9e9e7-25cf-49fd-b5ef-61aefed2897e
Host: upload.twitter.com
Content-Length: 2399916

–5fb9e9e7-25cf-49fd-b5ef-61aefed2897e
Content-Disposition: form-data; name=“media”; filename="d1cd395d-bebf-4733-aedc-680327ef63ec"
Content-Type: image/jpeg

Media Upload Response
HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-length: 140
content-type: application/json;charset=utf-8
date: Tue, 16 Dec 2014 20:56:57 UTC
expires: Tue, 31 Mar 1981 05:00:00 GMT
expires: Tue, 16 Dec 2014 21:56:57 GMT
last-modified: Tue, 16 Dec 2014 20:56:57 GMT
pragma: no-cache
server: tsa_b
set-cookie: lang=en
set-cookie: guest_id=v1%xxxxxxxx; Domain=.twitter.com; Path=/; Expires=Thu, 15-Dec-2016 20:56:57 UTC
status: 200 OK
strict-transport-security: max-age=631138519
x-access-level: read-write
x-connection-hash: xxxxxxxxxxx
x-frame-options: SAMEORIGIN
x-response-time: 344
x-transaction: xxxxxxxxx
x-xss-protection: 1; mode=block

{“media_id”:544959385899122689,“media_id_string”:“544959385899122689”,“size”:4311817,“image”:{“w”:3000,“h”:2350,“image_type”:“image/jpeg”}}

Status Update Request
POST https://api.twitter.com/1.1/statuses/update.json HTTP/1.1
Authorization: OAuth oauth_consumer_key=“xxxxxxxxxx”,oauth_nonce=“xxxxx”,oauth_signature=“xxxxxxxxxxxx”,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=“1418763469”,oauth_token=“xxxxxxxxxxx”,oauth_version="1.0a"
Content-Type: application/x-www-form-urlencoded
Host: api.twitter.com
Content-Length: 117

status=test%20test%20test&media_ids=544959385899122689%2C544959443889557504%2C544959458036957184%2C544959545941192705

Status Update Response
HTTP/1.1 400 Bad Request
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-length: 73
content-type: application/json;charset=utf-8
date: Tue, 16 Dec 2014 20:57:49 UTC
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Tue, 16 Dec 2014 20:57:49 GMT
pragma: no-cache
server: tsa_b
set-cookie: lang=en
set-cookie: guest_id=xxxxxx; Domain=.twitter.com; Path=/; Expires=Thu, 15-Dec-2016 20:57:49 UTC
status: 400 Bad Request
strict-transport-security: max-age=631138519
x-access-level: read-write
x-connection-hash: xxxxxxxx
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-response-time: 44
x-transaction: xxxxxxx
x-xss-protection: 1; mode=block

{“errors”:[{“code”:324,“message”:“The validation of media ids failed.”}]}


Creating tweet with image: "The validation of media ids failed"
Failure when trying to upload some images. "The validation of media ids failed."
#2

Thanks for the report - I’m investigating.


#3

@jason_rea … I am trying to uplaod media using rest…can u explain how did you achive. I was trying using SOAP UI but no luck.


#4

@mikkysa504 I already pretty much gave you everything you need to know in my post above, including the exact requests and responses to upload an image and then attach it to a Tweet. Summarizing heavily, what I did was:

  1. Create a Twitter app at apps.twitter.com.
  2. Generate tokens/secrets for the app and my user profile.
  3. Using C# and a .NET REST framework called Hammock, I wrote a method to upload an image byte stream to upload.twitter.com/1.1/media/upload.json and get back the media_id for the image. Then, I have another method to post a status update to api.twitter.com/1.1/statuses/update.json, optionally with media_ids. Hammock has a NuGet package available to easily add the dll to your project. There are also other .NET REST frameworks available, such as RestSharp. However, Hammock seems to play really nicely with the Twitter API. Also, TweetSharp is a nice wrapper that you can use to achieve your goals without having to do much work at all.

#5

@jason_rea …I faced same issue , If I am uploading an image without Content-Type: multipart/form-data.

But this is not in your case…Just sharing my experience.


#6

Are there any plans, now or in the future, to make changes to the API for this issue? I feel strongly that https://upload.twitter.com/1.1/media/upload.json should return an error code if the media exceeds the size limit. I also don’t see specific documentation about the types of errors that the media upload endpoint will return. Better yet, I see very little documentation about the media upload endpoint at all. I see it mentioned in the documentation for updating statuses, but that’s it.


#7

I definitely have plans to improve the documentation about media/upload.json in the future, but I’m on vacation now until January. We recently improved the error reporting for the endpoint (the “validation of media IDs” message is one of the new ones) so that needs to be reflected in the docs when I have a chance to get to it!


#8

Please resolve this the validation of media ids failed issue.
If the file is too big add a image scaling script please.


#9

I have the same problem.I have tried with differents size and picture but does not work.
Have you an idea ?


#10

Yeah, don’t even try to upload an image larger than 3 MB (mebibytes, aka 3*2^20 or 3145728 bytes) and it will work. The dimensions don’t seem to matter in the images I’ve tried.

If you’re getting a 200 response back from media/upload.json, you’re doing the image upload part right. If your code post a status update without an image works, you’re doing that part right too. If you’re getting the 324 response back from statuses/update.json, after getting the other two parts working, I can almost guarantee you that the image file is too large.


#11

Ok Thank you,
I am going to try


#12

But i do not understant, my media have correctly been uploaded because when i do this:
twurl -H upload.twitter.com -X POST “/1.1/media/upload.json” --file “medias/media.gif” --file-field “media”

return the following messsage: {“image”:{“w”:400,“h”:340,“image_type”:“image/gif”},“media_id”:5685904978503270
40,“media_id_string”:“568590497850327040”,“size”:1462}

But after, i’m trying to do this:

twurl -d ‘status=Testing twurl’ -d ‘media_ids=568590497850327040’ -X POST /1.1/statuses/update.json

return the following messsage:

{“errors”:[{“code”:324,“message”:“The validation of media ids failed.”}]}

Thank you for your help.


#13

Hmmm, your image looks to be well within the size requirements. I see you’re uploading a .gif. Is it animated? I haven’t gotten around to researching animated .gifs in Twitter’s API yet. I would do some investigation into that. I think I’ve seen people talking about it in the forums. It’s definitely crap that Twitter would give you a media_id back without honoring it.


#14

With jpeg return:

{“request”:"/1.1/media/upload.json",“error”:"[JPEG] Ran out of bytes to parse
(null)."}
when i try to upload :frowning:


#15

I’m also experiencing this problem

However, my files are all well within the maximum size limits (3MB), even if I sum the sizes of all images combined they total < 3MB.

I have been able to upload two different animated gifs without issue, but combining them to one message fails. However, uploading multiple JPGs / PNG / non-animated gifs seemed okay.

Additionally, if I post > 4 images I get an error too.

So, it seems that you get the error if

  • animated gifs when combined in one message
  • post more than the allowed 4 photos
  • exceed the maximum file size (not sure if thats per file or total upload size)

My full error is…

Exception: 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 - The validation of media ids failed.
code - 324


#16

Hi guys,
I am having the same problem.

That is the problem : with a statuses/show i get the id_str of a media, which has been tweeted by me from the web on my account.
But when trying to post statuses/update with this id in media_ids, I have the same 324 error code, “The validation of media ids failed.”

May someone have a solution ?

Thank’s a lot.


#17

The issue here is that once that media item has been attached to a Tweet, it cannot be reused. So you’d need to re-upload an image to attach to a new Tweet.


#18

Image upload works in localhost sometimes, but never works with the actual domain :frowning:

Gives 400 Error. Please fix it as soon as possible.


#19

A 400 is a “Bad Request”. Not the same as 324, which this thread is about. You have also not given details about the request/response you are experiencing.


#20

@jason_rea, I din’t give much details because I think it’s a problem with Twitter API. Because, the code I’ve works fine in localhost, but doesn’t work when the app is hosted. Everything else works fine, except the image upload :frowning:

Am using the following code:

authoVariable.post('media/upload', 
                      {'media': fs.readFileSync(req.files[file].path, { encoding: 'base64' })}, 
                       function(error, params, response){
                              if(error) console.log("media/upload error 1 "+error);
 });

am getting error media/upload error 1 Error: Status Code: 400