coanor
coanor

Reputation: 3962

Twitter API `status/update_with_media` return `404 Not Found`

My App need to update the status and add images to the update, so the status/update_with_media is the best choice. There is no library I can use on my platform, so I ported PorlarSSL(a SSL library written in C) and implemented the HTTP protocol on TCP protocol in C. Here is my codes to request the update_with_media API.

The TCP send buffer(include the HTTP header and post body) is:

POST /1/statuses/update_with_media.json HTTP/1.1
Accept: */*
Host: upload.twitter.com
Authorization: OAuth oauth_consumer_key="wafabKbGRc16RUWgQvD4g", oauth_nonce="UvA44TqLLGWlHy3TDU8BPgAAAAAD", oauth_signature="62FJbljZOk9vOHU7RYCIn%2Fyl68c%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1331134259", oauth_token="46043095-aRPvEBFqHEiDwM0wWURJskAkdrLIJGMLRqI5yx1Po", oauth_version="1.0"
Connection: Keep-Alive
Content-Length: 659
Content-Type: multipart/form-data; boundary=--xyz

----xyz
Content-Disposition: form-data; name="media[]"; filename="asddf.gif"
Content-Type: application/octet-stream

<binary-image-data>
----xyz
Content-Disposition: form-data; name="status"

hello word
----xyz--

These fields are separated by \r\n, the blank line is expect the \r\n, so I'm sure the format is correct. The TCP buffer(include the binary image data) then encrypted by SSL and then send to Twitter, but the returned body is a HTML doc, the HTTP header is

HTTP/1.1 404 Not Found
Date: Thu, 08 Mar 2012 06:16:46 GMT
Set-Cookie: k=10.34.145.134.1331187406993104; path=/; expires=Thu, 15-Mar-12 06:16:46 GMT; domain=.twitter.com
Last-Modified: Mon, 27 Feb 2012 21:57:35 GMT
Accept-Ranges: bytes
Content-Length: 12882
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Server: tfe

I want to know what this mean? Is the binary image data need to be encrypted by SSL? or the status/update_with_media do not need SSL and just HTTP post is sufficient? If the Content-Length is incorrect(for example, larger than the actual sending length), will it cause any problem?

My handshake with twitter is OK and I can request other data from Twitter, so my internet is OK.

Can anyone help me?

Upvotes: 1

Views: 2496

Answers (1)

Arne Roomann-Kurrik
Arne Roomann-Kurrik

Reputation: 1072

Which server are you connecting to? Photo uploads need to be directed to upload.twitter.com.

Additionally, Content-Disposition: from-data; name="media[]"; filename="asddf.gif" contains the typo from-data.

Upvotes: 2

Related Questions