Creating tweet with image: "The validation of media ids failed"

media

#1

I am trying to upload a small image using the POST media/upload endpoint and then attach it to a new tweet. The call to media/upload appears to be successful (it returns a media_id), but when I pass the returned media_id parameter to the statuses/update endpoint it returns error code 324 The validation of media ids failed.

Other users have encountered this problem when uploading large files (see here, and here), but the file I am testing with is only about 24 KB. I have no trouble creating a tweet at twitter.com and attaching the image, and my code to create a tweet without an image works just fine.

Here are examples of the requests to each endpoint and the responses received (as captured by Fiddler). The only changes I have made are to remove the binary data and replace some oauth parameters with xxxxxxx. I suspect that I have made some silly error in one of the requests - if anyone has any insights I would be very grateful.

Request to media/upload:

POST https://upload.twitter.com/1.1/media/upload.json HTTP/1.1
User-Agent: Aspcio 0.1
Authorization: OAuth oauth_consumer_key=“xxxxxxxxxxxxxxxxxxxx”, oauth_token=“xxxxxxxxxxxxxxxxxxxx”, oauth_nonce=“3664787”, oauth_signature=“xxxxxxxxxxxxxxxxxxxx”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1441426469”, oauth_version="1.0"
Content-Type: multipart/form-data; boundary=---------------------------8d2b5fc4fce81fe
Host: upload.twitter.com
Content-Length: 31844

-----------------------------8d2b5fc4fce81fe
Content-Disposition: form-data; name=“media”; filename="Lemur.png"
Content-Type: image/png

####Binary data omitted####
-----------------------------8d2b5fc4fce81fe–

Response from media/upload:

HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-disposition: attachment; filename=json.json
content-length: 161
content-type: application/json;charset=utf-8
date: Sat, 05 Sep 2015 04:14:33 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Sat, 05 Sep 2015 04:14:33 GMT
pragma: no-cache
server: tsa_a
set-cookie: lang=en; Path=/
set-cookie: guest_id=v1%3A144142647343008986; Domain=.twitter.com; Path=/; Expires=Mon, 04-Sep-2017 04:14:33 UTC
status: 200 OK
strict-transport-security: max-age=631138519
vary: Origin
x-access-level: read-write
x-connection-hash: 9a773440579e5fdc2ddae3dbf67b4052
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 415
x-rate-limit-remaining: 412
x-rate-limit-reset: 1441429968
x-response-time: 29
x-transaction: 9560cdb467ba4bb6
x-tsa-request-body-time: 566
x-twitter-response-tags: BouncerCompliant
x-xss-protection: 1; mode=block

{“media_id”:640015133712912384,“media_id_string”:“640015133712912384”,“size”:31654,“expires_after_secs”:86400,“image”:{“image_type”:“image/bmp”,“w”:100,“h”:79}}

Request to statuses/update:

POST https://api.twitter.com/1.1/statuses/update.json HTTP/1.1
User-Agent: Aspcio 0.1
Authorization: OAuth oauth_consumer_key=“xxxxxxxxxxxxxxxxxxxx”, oauth_token=“xxxxxxxxxxxxxxxxxxxx”, oauth_nonce=“2049548”, oauth_signature=“xxxxxxxxxxxxxxxxxxxx”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1441426470”, oauth_version="1.0"
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Host: api.twitter.com
Content-Length: 64

status=Tweet%20with%20lemur%20photo&media_ids=640015133712912384

Response from statuses/update:

HTTP/1.1 400 Bad Request
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-disposition: attachment; filename=json.json
content-length: 73
content-type: application/json;charset=utf-8
date: Sat, 05 Sep 2015 04:14:33 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Sat, 05 Sep 2015 04:14:33 GMT
pragma: no-cache
server: tsa_a
set-cookie: lang=en; Path=/
set-cookie: guest_id=v1%3A144142647367288845; Domain=.twitter.com; Path=/; Expires=Mon, 04-Sep-2017 04:14:33 UTC
status: 400 Bad Request
strict-transport-security: max-age=631138519
x-access-level: read-write
x-connection-hash: 8fcbfac521b0ca2bb80580bb8e942a82
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-response-time: 53
x-transaction: 067e5f809b5d4f91
x-tsa-request-body-time: 4
x-twitter-response-tags: BouncerCompliant
x-xss-protection: 1; mode=block

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