開発備忘録

備忘録

TwitterAPIを使い始めてみました

ある程度インスタのアプリが完成しつつあるので、

インスタ側に追加データのリクエストを申請し、あとは審査待ち。

 

その間にTwitterのアプリの方も手を付けようと思い、

あるサイトを参考にしてみた結果、Twitterから得られるjsonが複雑すぎてわろてる。

 

参考URL:

qiita.com

 

{

  1. statuses:[
    1. 0:{
      1. created_at:Sun Jun 13 08:00:02 +0000 2021
      2. id:1403985497861599200
      3. id_str:1403985497861599234
      4. text:Day 164 Journey of ACIM Text Chapter 13: XI. 1-5 https://t.co/FQBnvnQUkl #acim #acimtext ACIM LESSON 164 Meditatio… https://t.co/FMOovu8Bqt
      5. truncated:true
      6. entities:{
        1. hashtags:[
          1. 0:{
            1. text:acim
            2. indices:[
              1. 0:74
              2. 1:79
              ]
            }
          2. 1:{
            1. text:acimtext
            2. indices:[
              1. 0:80
              2. 1:89
              ]
            }
          ]
        2. symbols:
        3. user_mentions:
        4. urls:[
          1. 0:{
            1. url:https://t.co/FQBnvnQUkl
            2. expanded_url:https://youtu.be/vsiBSTniF4Y
            3. display_url:youtu.be/vsiBSTniF4Y
            4. indices:[
              1. 0:49
              2. 1:72
              ]
            }
          2. 1:{
            1. url:https://t.co/FMOovu8Bqt
            2. expanded_url:https://twitter.com/i/web/status/1403985497861599234
            3. display_url:twitter.com/i/web/status/1…
            4. indices:[
              1. 0:117
              2. 1:140
              ]
            }
          ]
        }
      7. metadata:{
        1. iso_language_code:en
        2. result_type:recent
        }
      8. source:<a href="https://www.ripl.com" rel="nofollow">Ripl App</a>
      9. in_reply_to_status_id:null
      10. in_reply_to_status_id_str:null
      11. in_reply_to_user_id:null
      12. in_reply_to_user_id_str:null
      13. in_reply_to_screen_name:null
      14. user:{
        1. id:35742622
        2. id_str:35742622
        3. name:Maureen L. Yarbrough
        4. screen_name:momohere
        5. location:Florida, USA
        6. description:Training in forgiveness. Educator. Life Care Services. ❤️ Ordained Minister Wedding & Funeral Officiator ❤️ Certified End of Life Doula
        7. url:https://t.co/FxxCj0DsmT
        8. entities:{
          1. url:{
            1. urls:[
              1. 0:{
                1. url:https://t.co/FxxCj0DsmT
                2. expanded_url:https://www.facebook.com/tismomo
                3. display_url:facebook.com/tismomo
                4. indices:[
                  1. 0:0
                  2. 1:23
                  ]
                }
              ]
            }
          2. description:{
            1. urls:
            }
          }
        9. protected:false
        10. followers_count:634
        11. friends_count:957
        12. listed_count:5
        13. created_at:Mon Apr 27 13:38:13 +0000 2009
        14. favourites_count:178
        15. utc_offset:null
        16. time_zone:null
        17. geo_enabled:true
        18. verified:false
        19. statuses_count:12722
        20. lang:null
        21. contributors_enabled:false
        22. is_translator:false
        23. is_translation_enabled:false
        24. profile_background_color:AADAAD
        25. profile_background_image_url:http://abs.twimg.com/images/themes/theme1/bg.png
        26. profile_background_image_url_https:https://abs.twimg.com/images/themes/theme1/bg.png
        27. profile_background_tile:true
        28. profile_image_url:http://pbs.twimg.com/profile_images/1281365824561971202/8-Audlty_normal.jpg
        29. profile_image_url_https:https://pbs.twimg.com/profile_images/1281365824561971202/8-Audlty_normal.jpg
        30. profile_banner_url:https://pbs.twimg.com/profile_banners/35742622/1594336395
        31. profile_link_color:55A16F
        32. profile_sidebar_border_color:0B2C04
        33. profile_sidebar_fill_color:116E4F
        34. profile_text_color:279247
        35. profile_use_background_image:true
        36. has_extended_profile:true
        37. default_profile:false
        38. default_profile_image:false
        39. following:false
        40. follow_request_sent:false
        41. notifications:false
        42. translator_type:none
        43. withheld_in_countries:
        }
      15. geo:null
      16. coordinates:null
      17. place:null
      18. contributors:null
      19. is_quote_status:false
      20. retweet_count:0
      21. favorite_count:0
      22. favorited:false
      23. retweeted:false
      24. possibly_sensitive:false
      25. lang:en
      }

 

例のごとく検索ワードは「オードリー」

するとjsonの相当深い第一層目が取得できた。。。インスタとは大違いだ。

 

今からこれの解読作業に移る。

{ …jsonの中身

 statuses… データの中身

 created_at …日付

 id …投稿id?(どうやって使うんだ...?)

 id_str …投稿id?とは別のid。本物の投稿idか?(※こっち側をURLに埋め込むと該当ツイートに飛べる)

 text …本文

 truncated …?

 entities{  

   hashtags {

    text …ハッシュタグの文字

    indices …?↓

  1.          0:108
  2.          1:113

 user:{

  1. id:940735939352997900
  2. id_str:940735939352997888
  3. name:もこ
  4. screen_name:moko030421
  5. location:日本
  6. description:松井珠理奈ちゃんを応援します😊無言でリツィート、いいねさせてもらいます。 初心者なので、迷惑をかけてしまったらすみません。
  7. url:null
  8. entities:{
    1. description:{
      1. urls:[]
  1. followers_count:62
  2. friends_count:70
  1. statuses_count:24343 …ツイート数