Api.twitter.com always return "Could not authenticate you" with curl cmd


#1

This is my curl cmd for api.twitter.com. It will return Could not authenticate you.

curl -i -v -X POST \
  -H "Authorization: OAuth oauth_nonce=...................................." \
  -d "status=Hello Twitter" \
  --trace . \
  https://api.twitter.com/1.1/statuses/update.json

However, when I use the same oauth header for upload.twitter.com, it works fine.

curl -i -v -X POST \
  -H "Authorization: OAuth oauth_nonce=.................................." \
  -F "media=@/home/yiwang/Desktop/mac_1024.jpg" \
  https://upload.twitter.com/1.1/media/upload.json 

I am 100% sure the oauth1 headers in both cases are the same.

Also I only see this through curl cmd. Through python-requests both cases works fine.


#2

This is the python http requests which works fine:

POST https://api.twitter.com/1.1/statuses/update.json
Content-Length: 60
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.13.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth oauth_nonce=..............

status=Hello+Twitter+1516987702&media_ids=956941901197914xxx

This is the curl cmd I built which return {“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}:

curl -i -v -X POST \
  -H "Content-Length: 60" \
  -H "Accept: */*" \
  -H "User-Agent: python-requests/2.13.0" \
  -H "Connection: keep-alive" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Authorization: OAuth oauth_nonce=.........." \
  -d "status=Hello+Twitter+1516987426&media_ids=956941901197914xxx" \
  --trace . \
  https://api.twitter.com/1.1/statuses/update.json

#3

Issue fixed by regenerate a base string including status for posting tweet.