cURL / Mailing Lists / curl-library / Single Mail

curl-library

multipart/form-data to post on twitter with image

From: Mohan R <mohan43u_at_gmail.com>
Date: Mon, 17 Sep 2012 21:07:32 +0530

Hi,

I'm new to libcurl mailing-list. Just want to get some clarification.
I'm trying to upload a picture using libcurl to twitter, but twitter is
refusing with 'Could not authenticate you' message. The same Oauth
tokens works without any issues for other endpoints except
https://api.twitter.com/1.1/statuses/update_with_media.json.

I'm posting my request here in the hope of atleast confirming that my
request is correct according to OAuth rules. Here is my request,

About to connect() to api.twitter.com port 443 (#0)
  Trying 199.59.149.232...
connected
Connected to api.twitter.com (199.59.149.232) port 443 (#0)
successfully set certificate verify locations:
  CAfile: none
  CApath: /etc/ssl/certs
SSLv3, TLS handshake, Client hello (1):
^ASSLv3, TLS handshake, Server hello (2):
^BSSLv3, TLS handshake, CERT (11):
^KSSLv3, TLS handshake, Server finished (14):
^NSSLv3, TLS handshake, Client key exchange (16):
^PSSLv3, TLS change cipher, Client hello (1):
^ASSLv3, TLS handshake, Finished (20):
^TSSLv3, TLS change cipher, Client hello (1):
^ASSLv3, TLS handshake, Finished (20):
^TSSL connection using RC4-SHA
Server certificate:
^I subject: C=US; ST=California; L=San Francisco; O=Twitter, Inc.;
OU=Twitter Security; CN=api.twitter.com
^I start date: 2012-05-02 00:00:00 GMT
^I expire date: 2013-05-03 23:59:59 GMT
^I subjectAltName: api.twitter.com matched
^I issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms
of use at https://www.verisign.com/rpa (c)09; CN=VeriSign Class 3 Secure
Server CA - G2
^I SSL certificate verify ok.
POST /1.1/statuses/update_with_media.json HTTP/1.1^M
User-Agent: libcurl/7.24.0 OpenSSL/1.0.0j zlib/1.2.6^M
Host: api.twitter.com^M
Accept: */*^M
Authorization: OAuth oauth_consumer_key="KyvIiiISSVySYeUL4Eqn0g",
oauth_nonce="ff9MlgFHN1ldW09W5diHNtEGyv",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1347885237",
oauth_token="15209179-ucH3onm2Gban1M7WcfAnKwGhmZIHKVcJP4f3kpwzj",
oauth_version="1.0", oauth_signature="8EO3WcVxOMDZWGQAufXui47Lt2Q%3D"^M
Content-Length: 135805^M
Content-Type: multipart/form-data;
boundary=----------------------------e0ac8b7f301e^M
^M
------------------------------e0ac8b7f301e^M
Content-Disposition: form-data; name="media[]";
filename="screenshot.png"^M
Content-Type: application/octet-stream^M
^M
[png data stripped]
------------------------------e0ac8b7f301e^M
Content-Disposition: form-data; name="status"^M
^M
testing%20by%20uploading%20~%2FPictures%2Fscreenshot.png^M
------------------------------e0ac8b7f301e--^M
HTTP/1.1 401 Unauthorized^M
Content-Type: application/json; charset=utf-8^M
Content-Length: 63^M
Date: Mon, 17 Sep 2012 12:34:33 UTC^M
Server: tfe^M
HTTP error before end of send, stop sending
^M
{"errors":[{"message":"Could not authenticate you","code":32}]}Closing
connection #0
SSLv3, TLS alert, Client hello (1):
^A

The code which produced this request is available here
https://github.com/mohan43u/tweetpts/blob/master/tweetpts-curlapi.c

Please someone help me to understand what is the problem with my
request? It would be much more helpful if someone point me to a working
implementation with libcurl for the above request.

Thanks in advance,
Mohan R

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-09-17