skip to Main Content

I would like to pull the data from Twitter REST API. I have created the consumer key, secret and Access token, secret. I have tried with “Test OAuth”, it generates a CURL command but if I change any one parameter then it is giving the below error.
Message: {“errors”:[{“code”:32,”message”:”Could not authenticate you.”}]}

Now I would like to call the twitter API using CURL in shell script for different screenNames.

I want a sample command some thing like mentioned below

curl –get ‘https://api.twitter.com/1.1/statuses/user_timeline.json‘ –data ‘count=2&screen_name=aswin’ APIKEY:”xxxxxx”,Acesstoken:”yyyyyyyy”

Thanks in advance.

Regards,
Aswin

3

Answers


  1. Chosen as BEST ANSWER

    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"'
    

  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search