Bookmark and Share

(Draft)

Get sample JSON data

We'll get some sample JSON data by using cURL to call Twitter's API.

2014 March

As of 2014 March Twitter API v1.1, the following method works.

  1. Go to Twitter app's home page and make a testing app such as https://apps.twitter.com/app/5928994/,
  2. click on the "Test OAuth" button to see various authentication metadata,
  3. click on "See OAuth signature for this request" button, and see more specialized authentication data, including a directly usable temporary cURL command for the RESTful request.

As an example

curl \
--get 'https://api.twitter.com/1.1/statuses/user_timeline.json' \
--data 'count=2&screen_name=twitterapi' \
--header 'Authorization: \
OAuth oauth_consumer_key="Iie5pLbQHTcvsNSL4Q9bQ", \
oauth_nonce="5ae19d9143cfec50b3990e19e8863b21", \
oauth_signature="NROfqSHW1BLMFwK8ePbZQfLzwaI%3D", \
oauth_signature_method="HMAC-SHA1", \
oauth_timestamp="1395206578", \
oauth_token="14663976-CN3V54WoIXzofcn697ooLjDRaNuHS0ZiEFLCMDyK4", \
oauth_version="1.0"' \
--verbose \
> twitter-api-get-output.json

obtains JSON data twitter-api-get-output.json.

Note this exact call is only valid for a few minutes after it was first created.

Example jq queries

Get all values of text:

$ cat twitter-api-get-output.json | jq '.[].text'
"Broadcasting the voices of WordPress users, one Tweet at a time https://t.co/XCkAskpXVB"
"RT @crashlytics: Announcing Crashlytics Labs Project: Beta Distribution http://t.co/JifugCbtU2 #androiddev #iosdev http://t.co/Y0e2Ahm9lI"
blog comments powered by Disqus