Help us understand the problem. What is going on with this article?

#Twitter #API で得た #JSON を #jq と #shell でパースして URLの一覧を得る例

More than 1 year has passed since last update.

Twitter #API で得た #JSON を #jq と #shell でパースして URLの一覧を得る例

Json example

{"created_at": "Sun Feb 17 04:10:32 +0000 2019", "id": 1096985221788884994, "id_str": "1096985221788884994", "full_text": "Twitter\u30b2\u30fc\u30e0\u7406\u8ad6\u3002\u6700\u8fd1\u306f\u30cf\u30fc\u30c8\u3068\u30ea\u30c4\u30a4\u30fc\u30c8\u3068\u30d5\u30a9\u30ed\u30fc\u306e\u4fa1\u5024\u4ea4\u63db\u306b\u3064\u3044\u3066\u8003\u3048\u308b\u3002\u30ea\u30c4\u30a4\u30fc\u30c8\u3057\u3066\u304f\u308c\u305f\u3089\u30cf\u30fc\u30c810\u500b\u306f\u9001\u308a\u305f\u3044\u6c17\u6301\u3061\u3002\u30d5\u30a9\u30ed\u30fc\u3055\u308c\u305f\u6642\u306f\u76f8\u624b\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u898b\u306b\u884c\u3063\u3066\u3001\u4f55\u304b\u826f\u3044\u30c4\u30a4\u30fc\u30c8\u304c\u306a\u3044\u304b\u3092\u63a2\u3059\u3002\u8ab0\u3067\u3082\u3084\u3063\u3066\u3044\u308b\u7121\u610f\u8b58\u306e\u30ae\u30d6\u30a2\u30f3\u30c9\u30c6\u30a4\u30af\u3002\u305d\u306e\u610f\u8b58\u5316\u3002#Twitter https://t.co/G5JzFuPSOP", "truncated": false, "display_text_range": [0, 144], "entities": {"hashtags": [{"text": "Twitter", "indices": [136, 144]}], "symbols": [], "user_mentions": [], "urls": [], "media": [{"id": 1096985217376542726, "id_str": "1096985217376542726", "indices": [145, 168], "media_url": "http://pbs.twimg.com/media/DzlGPj2VYAYUfq0.jpg", "media_url_https": "https://pbs.twimg.com/media/DzlGPj2VYAYUfq0.jpg", "url": "https://t.co/G5JzFuPSOP", "display_url": "pic.twitter.com/G5JzFuPSOP", "expanded_url": "https://twitter.com/YumaInaura/status/1096985221788884994/photo/1", "type": "photo", "sizes": {"medium": {"w": 83, "h": 89, "resize": "fit"}, "small": {"w": 83, "h": 89, "resize": "fit"}, "thumb": {"w": 83, "h": 83, "resize": "crop"}, "large": {"w": 83, "h": 89, "resize": "fit"}}}]}, "extended_entities": {"media": [{"id": 1096985217376542726, "id_str": "1096985217376542726", "indices": [145, 168], "media_url": "http://pbs.twimg.com/media/DzlGPj2VYAYUfq0.jpg", "media_url_https": "https://pbs.twimg.com/media/DzlGPj2VYAYUfq0.jpg", "url": "https://t.co/G5JzFuPSOP", "display_url": "pic.twitter.com/G5JzFuPSOP", "expanded_url": "https://twitter.com/YumaInaura/status/1096985221788884994/photo/1", "type": "photo", "sizes": {"medium": {"w": 83, "h": 89, "resize": "fit"}, "small": {"w": 83, "h": 89, "resize": "fit"}, "thumb": {"w": 83, "h": 83, "resize": "crop"}, "large": {"w": 83, "h": 89, "resize": "fit"}}}, {"id": 1096985217376505856, "id_str": "1096985217376505856", "indices": [145, 168], "media_url": "http://pbs.twimg.com/media/DzlGPj2U0AAKrKc.jpg", "media_url_https": "https://pbs.twimg.com/media/DzlGPj2U0AAKrKc.jpg", "url": "https://t.co/G5JzFuPSOP", "display_url": "pic.twitter.com/G5JzFuPSOP", "expanded_url": "https://twitter.com/YumaInaura/status/1096985221788884994/photo/1", "type": "photo", "sizes": {"medium": {"w": 102, "h": 85, "resize": "fit"}, "small": {"w": 102, "h": 85, "resize": "fit"}, "large": {"w": 102, "h": 85, "resize": "fit"}, "thumb": {"w": 85, "h": 85, "resize": "crop"}}}, {"id": 1096985217384931328, "id_str": "1096985217384931328", "indices": [145, 168], "media_url": "http://pbs.twimg.com/media/DzlGPj4VYAAL3bz.jpg", "media_url_https": "https://pbs.twimg.com/media/DzlGPj4VYAAL3bz.jpg", "url": "https://t.co/G5JzFuPSOP", "display_url": "pic.twitter.com/G5JzFuPSOP", "expanded_url": "https://twitter.com/YumaInaura/status/1096985221788884994/photo/1", "type": "photo", "sizes": {"medium": {"w": 90, "h": 109, "resize": "fit"}, "thumb": {"w": 90, "h": 90, "resize": "crop"}, "large": {"w": 90, "h": 109, "resize": "fit"}, "small": {"w": 90, "h": 109, "resize": "fit"}}}]}, "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>", "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": {"id": 473780756, "id_str": "473780756"}, "geo": null, "coordinates": null, "place": null, "contributors": null, "is_quote_status": false, "retweet_count": 0, "favorite_count": 0, "favorited": false, "retweeted": false, "possibly_sensitive": false, "lang": "ja"}
{"created_at": "Sun Feb 17 04:00:46 +0000 2019", "id": 1096982762702090240, "id_str": "1096982762702090240", "full_text": "RT @crazy_wada: \u50d5\u306f\u30b5\u30fc\u30d0\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u304c\u6b7b\u306c\u307b\u3069\u82e6\u624b\u3060\u3063\u305f\u3002\u30b5\u30fc\u30d0\uff1f\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\uff1f\u5225\u306b\u3044\u3089\u306a\u304f\u306d\uff1f\u3063\u3066\u601d\u3063\u3066\u305f\u3002\u3051\u308c\u3069\u3001\u5b9f\u969b\u306b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u307f\u3066\u3001\u3088\u308a\u30bd\u30d5\u30c8\u958b\u767a\u306b\u78e8\u304d\u304c\u304b\u304b\u3063\u305f\u3057\u3001\u60a9\u3093\u3067\u3044\u305f\u6642\u9593\u304c\u7121\u99c4\u3060\u3063\u305f\u3068\u611f\u3058\u305f\u3002\u7d50\u5c40\u3067\u304d\u306a\u3044\u7406\u7531\u3092\u4e26\u3079\u3066\u305f\u3060\u3051\u3060\u3063\u305f\u306a\u3041\u2026", "truncated": false, "display_text_range": [0, 140], "entities": {"hashtags": [], "symbols": [], "user_mentions": [{"screen_name": "crazy_wada", "name": "\u308f\u3060\u3063\u3057\u30fc", "id": 1064209186907598848, "id_str": "1064209186907598848", "indices": [3, 14]}], "urls": []}, "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>", "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": {"id": 473780756, "id_str": "473780756"}, "geo": null, "coordinates": null, "place": null, "contributors": null, "retweeted_status": {"created_at": "Sun Feb 17 03:18:34 +0000 2019", "id": 1096972143735099392, "id_str": "1096972143735099392", "full_text": "\u50d5\u306f\u30b5\u30fc\u30d0\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u304c\u6b7b\u306c\u307b\u3069\u82e6\u624b\u3060\u3063\u305f\u3002\u30b5\u30fc\u30d0\uff1f\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\uff1f\u5225\u306b\u3044\u3089\u306a\u304f\u306d\uff1f\u3063\u3066\u601d\u3063\u3066\u305f\u3002\u3051\u308c\u3069\u3001\u5b9f\u969b\u306b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u307f\u3066\u3001\u3088\u308a\u30bd\u30d5\u30c8\u958b\u767a\u306b\u78e8\u304d\u304c\u304b\u304b\u3063\u305f\u3057\u3001\u60a9\u3093\u3067\u3044\u305f\u6642\u9593\u304c\u7121\u99c4\u3060\u3063\u305f\u3068\u611f\u3058\u305f\u3002\u7d50\u5c40\u3067\u304d\u306a\u3044\u7406\u7531\u3092\u4e26\u3079\u3066\u305f\u3060\u3051\u3060\u3063\u305f\u306a\u3041\u3068\u3001\u98df\u308f\u305a\u5acc\u3044\u306f\u3084\u3081\u307e\u3057\u305f\u3002", "truncated": false, "display_text_range": [0, 137], "entities": {"hashtags": [], "symbols": [], "user_mentions": [], "urls": []}, "source": "<a href=\"http://twittbot.net/\" rel=\"nofollow\">twittbot.net</a>", "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": {"id": 1064209186907598848, "id_str": "1064209186907598848"}, "geo": null, "coordinates": null, "place": null, "contributors": null, "is_quote_status": false, "retweet_count": 4, "favorite_count": 21, "favorited": true, "retweeted": true, "lang": "ja"}, "is_quote_status": false, "retweet_count": 4, "favorite_count": 0, "favorited": true, "retweeted": true, "lang": "ja"}
{"created_at": "Sun Feb 17 04:00:26 +0000 2019", "id": 1096982679109529600, "id_str": "1096982679109529600", "full_text": "RT @curiosity_com: \u301020\u6b73\u306f\u82e5\u304f\u306a\u3044\u3011\n\n20\u6b73\u306f\u3044\u3044\u5927\u4eba\u3002\n\n\u30de\u30b8\u3067\u3073\u3063\u304f\u308a\u3059\u308b\u3051\u3069\u3001\n\u300c\u89aa\u306b\u76f8\u8ac7\u3057\u3066\u304b\u3089...\u300d\n\u3068\u304b\u8a00\u3046\u4eba\u304c\u672c\u5f53\u306b\u591a\u3044\u3002\n\n\u81ea\u5206\u306e\u4eba\u751f\u306a\u306e\u306b\u3001\n\u9078\u629e\u6a29\u3092\u4ed6\u4eba\u306b\u59d4\u306d\u3093\u306e\u304b\u3044\u3002\n\u3063\u3066\u3002\n\n\u81ea\u5206\u3067\u7a3c\u3044\u3067\u3001\n\u81ea\u5206\u3067\u6c7a\u65ad\u3057\u3066\u3001\n\u81ea\u5206\u3067\u8cac\u4efb\u3092\u3068\u308b\u3002\u2026", "truncated": false, "display_text_range": [0, 140], "entities": {"hashtags": [], "symbols": [], "user_mentions": [{"screen_name": "curiosity_com", "name": "\u3086\u305a\u3059\u3051\ud83c\udf4a\u30b3\u30f3\u30c6\u30f3\u30c4\u30d3\u30b8\u30cd\u30b9", "id": 938807378266296321, "id_str": "938807378266296321", "indices": [3, 17]}], "urls": []}, "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>", "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": {"id": 473780756, "id_str": "473780756"}, "geo": null, "coordinates": null, "place": null, "contributors": null, "retweeted_status": {"created_at": "Sun Feb 17 02:29:18 +0000 2019", "id": 1096959743858376705, "id_str": "1096959743858376705", "full_text": "\u301020\u6b73\u306f\u82e5\u304f\u306a\u3044\u3011\n\n20\u6b73\u306f\u3044\u3044\u5927\u4eba\u3002\n\n\u30de\u30b8\u3067\u3073\u3063\u304f\u308a\u3059\u308b\u3051\u3069\u3001\n\u300c\u89aa\u306b\u76f8\u8ac7\u3057\u3066\u304b\u3089...\u300d\n\u3068\u304b\u8a00\u3046\u4eba\u304c\u672c\u5f53\u306b\u591a\u3044\u3002\n\n\u81ea\u5206\u306e\u4eba\u751f\u306a\u306e\u306b\u3001\n\u9078\u629e\u6a29\u3092\u4ed6\u4eba\u306b\u59d4\u306d\u3093\u306e\u304b\u3044\u3002\n\u3063\u3066\u3002\n\n\u81ea\u5206\u3067\u7a3c\u3044\u3067\u3001\n\u81ea\u5206\u3067\u6c7a\u65ad\u3057\u3066\u3001\n\u81ea\u5206\u3067\u8cac\u4efb\u3092\u3068\u308b\u3002\n\n\u3067\u3001\u5931\u6557\u3057\u3066\u6b7b\u306b\u304b\u3051\u305f\u3089\u3001\n\u89aa\u306b\u76f8\u8ac7\u3057\u307e\u3057\u3087\u3046\u3002", "truncated": false, "display_text_range": [0, 146], "entities": {"hashtags": [], "symbols": [], "user_mentions": [], "urls": []}, "source": "<a href=\"http://twittbot.net/\" rel=\"nofollow\">twittbot.net</a>", "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": {"id": 938807378266296321, "id_str": "938807378266296321"}, "geo": null, "coordinates": null, "place": null, "contributors": null, "is_quote_status": false, "retweet_count": 11, "favorite_count": 71, "favorited": true, "retweeted": true, "lang": "ja"}, "is_quote_status": false, "retweet_count": 11, "favorite_count": 0, "favorited": true, "retweeted": true, "lang": "ja"}

Run example

.id じゃだめ

$ cat log/timeline.json | head -n 3 | jq --raw-output .id_str  | sed 's/^/https:\/\/twitter.com\/YumaInaura\/status\//g'
https://twitter.com/YumaInaura/status/1096985221788884994
https://twitter.com/YumaInaura/status/1096982762702090240
https://twitter.com/YumaInaura/status/1096982679109529600

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/609

YumaInaura
Ruby on Rails 業務経験 約5年 / Perl PHP Python Golang Linux Apache MySQL BigQuery Jenkins ansible AWS など / いなうらゆうま / YumaInaura / 稲浦悠馬
http://twitter.com/yumainaura
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away