ものづくりのブログ

うちのネコを題材にしたものづくりができたらいいなと思っていろいろ奮闘してます。

twitter api v2 を使って色々なツイート情報を取得してみる。

Twitter API を使ってツイートを取得してみました。

twitter api v2

ドキュメント

developer.twitter.com

ツイート情報

乃木坂46のツイート(id:1469316238299914247)

"/2/tweets/1469316238299914247?expansions=attachments.media_keys,attachments.poll_ids,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id&tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,reply_settings,source,text,withheld&media.fields=duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics,non_public_metrics,organic_metrics,promoted_metrics,alt_text,variants&place.fields=contained_within,country,country_code,full_name,geo,id,name,place_type&poll.fields=duration_minutes,end_datetime,id,options,voting_status&user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld"
{
  "data": {
    "public_metrics": {
      "retweet_count": 1240,
      "reply_count": 17,
      "like_count": 10973,
      "quote_count": 86
    },
    "entities": {
      "urls": [
        {
          "start": 68,
          "end": 91,
          "url": "https://t.co/DzKeBqAnQm",
          "expanded_url": "http://dlvr.it/SF6qNh",
          "display_url": "dlvr.it/SF6qNh",
          "status": 404,
          "unwound_url": "https://www.nogizaka46.com/news/2021/12/post-2110281.php?utm_source=dlvr.it&utm_medium=twitter&utm_campaign=officialnews"
        },
        {
          "start": 92,
          "end": 115,
          "url": "https://t.co/PPUPJN2Wwb",
          "expanded_url": "https://twitter.com/nogizaka46/status/1469316238299914247/photo/1",
          "display_url": "pic.twitter.com/PPUPJN2Wwb",
          "media_key": "3_1469316236475461634"
        }
      ],
      "annotations": [
        {
          "start": 10,
          "end": 15,
          "probability": 0.4116,
          "type": "Other",
          "normalized_text": "乃木坂配信中"
        },
        {
          "start": 42,
          "end": 43,
          "probability": 0.4915,
          "type": "Person",
          "normalized_text": "筒井"
        }
      ]
    },
    "source": "dlvr.it",
    "attachments": {
      "media_keys": [
        "3_1469316236475461634"
      ]
    },
    "author_id": "317684165",
    "text": "【ニュース更新】 「乃木坂配信中」にて【食わず嫌い】見破ることはできるか? 掛橋VS筒井 初めて食べるものを当てるゲーム【対決】公開! https://t.co/DzKeBqAnQm https://t.co/PPUPJN2Wwb",
    "id": "1469316238299914247",
    "reply_settings": "everyone",
    "possibly_sensitive": false,
    "conversation_id": "1469316238299914247",
    "created_at": "2021-12-10T14:41:04.000Z",
    "lang": "ja",
    "context_annotations": [
      {
        "domain": {
          "id": "10",
          "name": "Person",
          "description": "Named people in the world like Nelson Mandela"
        },
        "entity": {
          "id": "1022870882086047745",
          "name": "Nogizaka 46",
          "description": "Nogizaka 46 (乃木坂46)"
        }
      },
      {
        "domain": {
          "id": "54",
          "name": "Musician",
          "description": "A musician in the world, like Adele or Bob Dylan"
        },
        "entity": {
          "id": "1022870882086047745",
          "name": "Nogizaka 46",
          "description": "Nogizaka 46 (乃木坂46)"
        }
      },
      {
        "domain": {
          "id": "55",
          "name": "Music Genre",
          "description": "A category for a musical style, like Pop, Rock, or Rap"
        },
        "entity": {
          "id": "810938095772123136",
          "name": "J-pop",
          "description": "J-POP"
        }
      },
      {
        "domain": {
          "id": "69",
          "name": "News Vertical",
          "description": "News Categories like Entertainment or Technology"
        },
        "entity": {
          "id": "1034501001544257536",
          "name": "Gaming news",
          "description": "Gaming News"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "810938095772123136",
          "name": "J-pop",
          "description": "J-POP"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "847524658970636288",
          "name": "Music",
          "description": "Music and radio"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "847527650667094017",
          "name": "Gaming",
          "description": "Gaming"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "1022870882086047745",
          "name": "Nogizaka 46",
          "description": "Nogizaka 46 (乃木坂46)"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "1034501001544257536",
          "name": "Gaming news",
          "description": "Gaming News"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "1046545033657081857",
          "name": "News",
          "description": "News"
        }
      }
    ]
  },
  "includes": {
    "media": [
      {
        "url": "https://pbs.twimg.com/media/FGQPVRHVcAIJKaX.jpg",
        "width": 1280,
        "height": 720,
        "media_key": "3_1469316236475461634",
        "type": "photo"
      }
    ],
    "users": [
      {
        "username": "nogizaka46",
        "description": "AKB48公式ライバルとして結成したアイドルグループです。\r\nグループ名の「乃木坂」は、最終オーディション会場の「SME乃木坂ビル」に由来し「46」は、『AKB48より人数が少なくても負けないという意気込み(秋元康氏)』からです。よろしくお願いします。",
        "pinned_tweet_id": "1555026326385754112",
        "id": "317684165",
        "created_at": "2011-06-15T09:35:11.000Z",
        "url": "http://t.co/f7TOymAV8b",
        "profile_image_url": "https://pbs.twimg.com/profile_images/879321670640558081/LJqAoLcs_normal.jpg",
        "protected": false,
        "entities": {
          "url": {
            "urls": [
              {
                "start": 0,
                "end": 22,
                "url": "http://t.co/f7TOymAV8b",
                "expanded_url": "http://www.nogizaka46.com/",
                "display_url": "nogizaka46.com"
              }
            ]
          }
        },
        "name": "乃木坂46",
        "verified": true,
        "location": "乃木坂",
        "public_metrics": {
          "followers_count": 2083483,
          "following_count": 20,
          "tweet_count": 30884,
          "listed_count": 7476
        }
      }
    ]
  }
}
スプラトゥーンのツイート(id:1564538423834460160)

"/2/tweets/1564538423834460160?expansions=attachments.media_keys,attachments.poll_ids,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id&tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,reply_settings,source,text,withheld&media.fields=duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics,non_public_metrics,organic_metrics,promoted_metrics,alt_text,variants&place.fields=contained_within,country,country_code,full_name,geo,id,name,place_type&poll.fields=duration_minutes,end_datetime,id,options,voting_status&user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld"
{
  "data": {
    "conversation_id": "1564538423834460160",
    "context_annotations": [
      {
        "domain": {
          "id": "71",
          "name": "Video Game",
          "description": "A video game like Overwatch"
        },
        "entity": {
          "id": "854949050151452672",
          "name": "Splatoon",
          "description": "This entity includes all conversation about the franchise, as well as any individual installments in the series, if applicable.\t\t\t"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "847527650667094017",
          "name": "Gaming",
          "description": "Gaming"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "854949050151452672",
          "name": "Splatoon",
          "description": "This entity includes all conversation about the franchise, as well as any individual installments in the series, if applicable.\t\t\t"
        }
      },
      {
        "domain": {
          "id": "131",
          "name": "Unified Twitter Taxonomy",
          "description": "A taxonomy view into the Semantic Core knowledge graph"
        },
        "entity": {
          "id": "1070028159964262400",
          "name": "Video games"
        }
      }
    ],
    "source": "Beluga_Production",
    "entities": {
      "annotations": [
        {
          "start": 57,
          "end": 62,
          "probability": 0.4097,
          "type": "Other",
          "normalized_text": "サーモンラン"
        },
        {
          "start": 81,
          "end": 95,
          "probability": 0.3504,
          "type": "Organization",
          "normalized_text": "Nintendo Switch"
        }
      ],
      "urls": [
        {
          "start": 130,
          "end": 153,
          "url": "https://t.co/XanMoy1szn",
          "expanded_url": "https://twitter.com/SplatoonJP/status/1564538423834460160/photo/1",
          "display_url": "pic.twitter.com/XanMoy1szn",
          "media_key": "3_1564415572250488832"
        }
      ]
    },
    "lang": "ja",
    "id": "1564538423834460160",
    "attachments": {
      "media_keys": [
        "3_1564415572250488832"
      ]
    },
    "reply_settings": "everyone",
    "possibly_sensitive": false,
    "public_metrics": {
      "retweet_count": 3773,
      "reply_count": 750,
      "like_count": 36464,
      "quote_count": 237
    },
    "created_at": "2022-08-30T09:00:02.000Z",
    "author_id": "2888006497",
    "text": "バンカラ街にある遊戯施設「イカッチャ」は、近くの人とローカル通信を楽しむための場所だ。\n「プライベートマッチ」と「サーモンラン」を遊ぶことができるぞ。\n友達同士でNintendo Switchを持ち寄って、ワイワイガヤガヤ楽しもう。\nイカなきゃ、イカッチャ! https://t.co/XanMoy1szn"
  },
  "includes": {
    "media": [
      {
        "height": 1080,
        "width": 1920,
        "type": "photo",
        "media_key": "3_1564415572250488832",
        "url": "https://pbs.twimg.com/media/FbXrrKEUcAAP-Fk.jpg"
      }
    ],
    "users": [
      {
        "id": "2888006497",
        "created_at": "2014-11-03T01:36:06.000Z",
        "name": "Splatoon(スプラトゥーン)",
        "description": "『スプラトゥーン』公式総合アカウント。イカ研究所の調査報告(ゲーム情報)やお知らせをお伝えします。ご質問・お問い合わせにはお答えしておりませんのでご容赦ください。最新作の『スプラトゥーン3』は2022年9月9日(金)発売予定。 ※イカ研究所は実在の人物、団体とは一切関係ございません。",
        "url": "https://t.co/ApvYrZXfIB",
        "protected": false,
        "public_metrics": {
          "followers_count": 1714230,
          "following_count": 1,
          "tweet_count": 3764,
          "listed_count": 9827
        },
        "profile_image_url": "https://pbs.twimg.com/profile_images/1362173855100334082/sg2p-G27_normal.jpg",
        "username": "SplatoonJP",
        "entities": {
          "url": {
            "urls": [
              {
                "start": 0,
                "end": 23,
                "url": "https://t.co/ApvYrZXfIB",
                "expanded_url": "https://www.nintendo.co.jp/switch/av5ja/index.html",
                "display_url": "nintendo.co.jp/switch/av5ja/i…"
              }
            ]
          }
        },
        "verified": true
      }
    ]
  }
}