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
I found the answer.
Because most twitter requests require calculating the oauth signature, you should either write a client yourself or reuse an existing command line client.
As you saw any change to the request will generally invalidate the query, and even time is one of the inputs.
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.