Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Twitter REST API v1.1 using curl?

Using the "Test OAuth" feature (application settings) I can generate a fully set up curl command for a specified API request:

curl --get 'https://api.twitter.com/1.1/followers/ids.json' 
  --data 'count=10&cursor=-1&screen_name=microsoft' 
  --header 'Authorization: OAuth 
      oauth_consumer_key="123consumer", 
      oauth_nonce="123nonce", 
      oauth_signature="123signature%3D", 
      oauth_signature_method="HMAC-SHA1", 
      oauth_timestamp="1402309080", 
      oauth_token="123-token", 
      oauth_version="1.0"' 
  --verbose 

This is exactly what I would like to do but with varying API requests. But just exchanging "microsoft" in above command with "google" will cause an error:

{"errors":[{"message":"Could not authenticate you","code":32}]}

Why is that not possible and how can I make it work?


As far as I understand OAuth all I need for authorizing a request is the oauth-key/values listed in step G of the following chart:

chart


This is the "official" answer: Authorizing a request

like image 318
Raffael Avatar asked Jun 09 '14 10:06

Raffael


People also ask

Can I still use Twitter API v1 1?

The v1. 1 search/tweets and the Twitter API v2 recent search endpoint support both OAuth 1.0a User Context and OAuth 2.0 App-Only. Therefore, if you were previously using the standard v1. 1 search endpoint you can continue using the same authentication method if you migrate to the Twitter API v2 version.

Does cURL use REST API?

curl can send all common HTTP commands to a REST API including GET , POST , PUT , and DELETE . The curl utility is straightforward to use. It has a few main options for data transmission, user authentication, and making header changes.


1 Answers

When you change the parameters, the OAuth signature base string does change, so the oauth_signature header does also change. That's why you can't reuse the signature when you change the parameters.

If you want to see the curl request for any specific request to Twitter API, have a look at the STTwitter library for OS X. The demo project includes a GUI client that will show you the OAuth request in curl format.

Now if your goal is just issuing requests to Twitter from command line, check out twurl which is a command-line client for Twitter API.

like image 169
nst Avatar answered Oct 23 '22 11:10

nst