How to make Twitter API call through curl in unix How to make Twitter API call through curl in unix curl curl

How to make Twitter API call through curl in unix


I found the answer.

curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' \     --data 'count=2&screen_name=twitterapi' \     --header 'Authorization: OAuth oauth_consumer_key="AAAAAAAAAAAAAAAAAAAA", oauth_nonce="BBBBBBBBBBBBBBBBBBBBBBB", oauth_signature="CCCCCCCCCCCCCCCCCCCCCCCCCCC", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1471672391", oauth_token="DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", oauth_version="1.0"'


Since your specific query doesn't require a user context you can use Application only authentication to make this request. The bearer token won't change per request so it should allow you to keep using curl.

https://dev.twitter.com/oauth/application-only

n.b. it won't work for all endpoints, but should for the case you listed.


Because most twitter requests require calculating the oauth signature, you should either write a client yourself or reuse an existing command line client.

  1. https://github.com/twitter/twurl
  2. https://github.com/sferik/t
  3. https://github.com/yschimke/oksocial/wiki (Mac focused/cross service)

As you saw any change to the request will generally invalidate the query, and even time is one of the inputs.