pages tagged jq http://meng6net.localhost/tag/jq/ <p><small>Copyright © 2005-2020 by <code>Meng Lu &lt;lumeng3@gmail.com&gt;</code></small></p> Meng Lu's home page ikiwiki Tue, 16 May 2017 23:59:39 +0000 Examples of using jq http://meng6net.localhost/computing/example/examples_of_using_jq/ http://meng6net.localhost/computing/example/examples_of_using_jq/ computing example jq twitter Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <p>(Draft)</p> <h2>Get sample JSON data</h2> <p>We'll get some sample JSON data by using cURL to call Twitter's API.</p> <h3>2014 March</h3> <p>As of 2014 March Twitter API v1.1, the following method works.</p> <ol> <li>Go to Twitter app's home page and make a testing app such as https://apps.twitter.com/app/5928994/,</li> <li>click on the <a href= "https://dev.twitter.com/apps/5928994/oauth">"Test OAuth" button</a> to see various authentication metadata,</li> <li>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.</li> </ol> <p>As an example</p> <pre><code>curl \ --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' \ --data 'count=2&amp;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 \ &gt; twitter-api-get-output.json </code></pre> <p>obtains JSON data <a href= "http://meng6.net/pages/computing/example/examples_of_using_jq/twitter-api-get-output.json"> <code>twitter-api-get-output.json</code></a>.</p> <p>Note this exact call is only valid for a few minutes after it was first created.</p> <h2>Example jq queries</h2> <p>Get all values of <code>text</code>:</p> <pre><code>$ 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" </code></pre>