{"id":162324,"date":"2022-10-18T13:52:35","date_gmt":"2022-10-18T17:52:35","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=162324"},"modified":"2022-11-21T09:59:10","modified_gmt":"2022-11-21T14:59:10","slug":"how-to-get-tweets-using-python-and-twitter-api-v2-part-ii","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/","title":{"rendered":"How to get Tweets using Python and Twitter API v2 \u2013 Part II"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"get-tweet-s-with-tweet-id-s-using-client\">Get Tweet(s) with Tweet Id(s) using client<\/h3>\n\n\n\n<p>We can fetch a tweet given its tweet id using the get_tweet() method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tweet_id = '1532694058916753410'\n\n# Get tweet with a given tweet id\ntweet = client.get_tweet(id=tweet_id)\nprint(f\"The tweet with id {tweet_id} is:\\n\")\nprint(tweet.data.text)  <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/d9a1624e43de7615a99d1838854587aa#file-get_tweet_text-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_tweet_text.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>What if we want to get the tweets for multiple tweet ids? The approach is similar to the above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tweet_ids= &#91;'1532694058916753410', '1532693690224758784', '1532694050523860992']\n\n# Get tweet with a given tweet id\ntweets = client.get_tweets(ids=tweet_ids)\n\nfor tweet in tweets.data:\n    print(f\"The tweet with id {tweet.id} is:\\n\")\n    print(tweet.text,\"\\n\",50*\"-\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/efb71522cf341eb8990a7f16b060f6b8#file-get_tweets_from_multiple_ids-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_tweets_from_multiple_ids.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"get-a-user-s-followers-using-client\">Get a user\u2019s followers using client<\/h3>\n\n\n\n<p>Would you like to now check the followers a user has? Let us see how you can do that.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>id = \"869660137\"\n\nfollowers = client.get_users_followers(id=id)\n\nprint(\"These are the people following this user:\")\n\nfor count, follower in enumerate(followers.data):\n    print(count+1,follower)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/728a39a85854f6a48e01caa3755b0440#file-get_followers-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_followers.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Get users that the user follows using client<\/h3>\n\n\n\n<p>And who does this user follow? You may be interested to know that too.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>id = \"869660137\"\n\nfollowed = client.get_users_following(id=id)\n\nprint(f\"This user follows {len(followed&#91;0])} users.\\n\")\n\nprint(\"This user follows the following:\\n\")\nfor count, f in enumerate(followed.data):\n    print(count+1, f\"User ID: {f.id}    Name: {f.name}\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/58b76be37a2ebb001cfacfe5579e6994#file-get_followed_persons_from_user-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_followed_persons_from_user.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Get a user\u2019s Tweets using client<\/h3>\n\n\n\n<p>Similar to how we fetched a user\u2019s tweet using API, we can fetch a user\u2019s tweets using the client\u2019s&nbsp;<strong>get_users_tweets()<\/strong>&nbsp;method. By default, we will have values only for the tweet id and the text in the response. If we want to access the other tweet fields&nbsp;<a href=\"https:\/\/developer.twitter.com\/en\/docs\/twitter-api\/data-dictionary\/object-model\/tweet\" target=\"_blank\" rel=\"noreferrer noopener\">\u207d\u2075\u207e<\/a>, we will have to specify them separately, as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Shall we check out this user's tweets?\nname = 'elonmusk'\n\n# Fetch user data\nuser=client.get_user(username=name).data\n\n# Extract the user id and user name\nuser_id = user.id\nuser_name = user.name\n\n# Fetch tweets by the user\ntweets = client.get_users_tweets(id=user_id, tweet_fields=&#91;'id', 'text', 'created_at', 'context_annotations'])\n\nprint(f\"Here are the recent tweets by {user_name}:\\n\")\n\nfor tweet in tweets.data:\n    print(tweet.created_at,'\\n', tweet,\"\\n\", tweet.context_annotations,\"\\n\\n\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/2124445a9f482c32f4795f007b2c8265#file-get_user_tweets-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_user_tweets.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Get Tweets that a user liked using client<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>id = \"869660137\"\n\ntweets = client.get_liked_tweets(id=id)\n\nfor count, tweet in enumerate(tweets.data):\n    print(count+1, \"(\", tweet.id, \")\", tweet, \"\\n\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/425506773cc26cbd01bb4431d7972744#file-get_liked_tweets-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_liked_tweets.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Get users who Retweeted a Tweet using client<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>tweet_id = '1533413197629296640'\n\nretweeters = client.get_retweeters(id=tweet_id)\n\nfor count, users in enumerate(retweeters.data):\n    print(count+1, users)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/004aa86735105a908ec33e66f962ae88#file-get_users_that_retweeted-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_users_that_retweeted.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"search-recent-tweets-using-client\">Search recent Tweets using client<\/h3>\n\n\n\n<p>The&nbsp;<strong>search_recent_tweets()<\/strong>&nbsp;method returns tweets from the last seven days that match the given search query. You can also specify the start and end times for the search.<\/p>\n\n\n\n<p>By default, the search results will be in the form of a response containing the tweet ID and tweet text. Please note that the max_results parameter can only have a value between 10 and 100.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query = 'from:quantinsti -is:retweet'\n\ntweets = client.search_recent_tweets(query=query, max_results=100)\n\nfor tweet in tweets.data:\n    print(tweet.text)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/771228e098a487b9086e933b3ea54bde#file-search_recent_tweets-py\" target=\"_blank\" rel=\"noreferrer noopener\">search_recent_tweets.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"get-tweet-count-for-a-search-query-using-client\">Get Tweet count for a search query using client<\/h3>\n\n\n\n<p>How many tweets about Elon Musk were there recently in English which were not retweets? Let us see how we can get a count of such tweets using the get_recent_tweets_count() method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Search for queries in English language with 'elon musk' that are not retweets\nquery = 'elon musk lang:en -is:retweet'\n\n# Granularity can be minute, hour, day\ncounts = client.get_recent_tweets_count(query=query, granularity='day')\n\nfor count in counts.data:\n    print(count)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/89e5ec97867daf13f512811e74f5b104#file-get_tweet_count-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_tweet_count.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>Head to this&nbsp;<a href=\"https:\/\/developer.twitter.com\/en\/docs\/twitter-api\/tweets\/search\/integrate\/build-a-query\" target=\"_blank\" rel=\"noreferrer noopener\">\u207d\u2076\u207e<\/a>&nbsp;link if you would like to know more about building queries for searching tweets.<\/p>\n\n\n\n<p><em>Stay tuned for Part III to learn about Pagination in client<\/em>.<\/p>\n\n\n\n<p><em>Visit QuantInsti for additional insights on this topic:&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/twitter-api-v2\/\">https:\/\/blog.quantinsti.com\/twitter-api-v2\/<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can fetch a tweet given its tweet id using the get_tweet() method.<\/p>\n","protected":false},"author":731,"featured_media":83281,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,349,338,350,341,344],"tags":[806,12968,12901,12967,865,595,12899,12357,12358],"contributors-categories":[13654],"class_list":{"0":"post-162324","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-python-development","10":"category-ibkr-quant-news","11":"category-quant-asia-pacific","12":"category-quant-development","13":"category-quant-regions","14":"tag-data-science","15":"tag-get_liked_tweets-py","16":"tag-get_trends-py","17":"tag-get_tweet_count-py","18":"tag-github","19":"tag-python","20":"tag-search_last_30_days-py","21":"tag-tweepy","22":"tag-twitter-api","23":"contributors-categories-quantinsti"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to get Tweets using Python and Twitter API v2 \u2013 Part II<\/title>\n<meta name=\"description\" content=\"We can fetch a tweet given its tweet id using the get_tweet() method.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/162324\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get Tweets using Python and Twitter API v2 \u2013 Part II | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"We can fetch a tweet given its tweet id using the get_tweet() method.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-18T17:52:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:59:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Udisha Alok\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Udisha Alok\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Udisha Alok\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/7faa788f12ff54d5d598292f5a252fab\"\n\t            },\n\t            \"headline\": \"How to get Tweets using Python and Twitter API v2 \u2013 Part II\",\n\t            \"datePublished\": \"2022-10-18T17:52:35+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:59:10+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/\"\n\t            },\n\t            \"wordCount\": 348,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/python-tile.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"get_liked_tweets.py\",\n\t                \"get_trends.py\",\n\t                \"get_tweet_count.py\",\n\t                \"GitHub\",\n\t                \"Python\",\n\t                \"search_last_30_days.py\",\n\t                \"Tweepy\",\n\t                \"Twitter API\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Asia Pacific\",\n\t                \"Quant Development\",\n\t                \"Quant Regions\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/\",\n\t            \"name\": \"How to get Tweets using Python and Twitter API v2 \u2013 Part II | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/python-tile.jpg\",\n\t            \"datePublished\": \"2022-10-18T17:52:35+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:59:10+00:00\",\n\t            \"description\": \"We can fetch a tweet given its tweet id using the get_tweet() method.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/python-tile.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/python-tile.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Python\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/7faa788f12ff54d5d598292f5a252fab\",\n\t            \"name\": \"Udisha Alok\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/udisha-alok\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to get Tweets using Python and Twitter API v2 \u2013 Part II","description":"We can fetch a tweet given its tweet id using the get_tweet() method.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/162324\/","og_locale":"en_US","og_type":"article","og_title":"How to get Tweets using Python and Twitter API v2 \u2013 Part II | IBKR Quant Blog","og_description":"We can fetch a tweet given its tweet id using the get_tweet() method.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/","og_site_name":"IBKR Campus US","article_published_time":"2022-10-18T17:52:35+00:00","article_modified_time":"2022-11-21T14:59:10+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg","type":"image\/jpeg"}],"author":"Udisha Alok","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Udisha Alok","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/"},"author":{"name":"Udisha Alok","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/7faa788f12ff54d5d598292f5a252fab"},"headline":"How to get Tweets using Python and Twitter API v2 \u2013 Part II","datePublished":"2022-10-18T17:52:35+00:00","dateModified":"2022-11-21T14:59:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/"},"wordCount":348,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg","keywords":["Data Science","get_liked_tweets.py","get_trends.py","get_tweet_count.py","GitHub","Python","search_last_30_days.py","Tweepy","Twitter API"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Asia Pacific","Quant Development","Quant Regions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/","name":"How to get Tweets using Python and Twitter API v2 \u2013 Part II | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg","datePublished":"2022-10-18T17:52:35+00:00","dateModified":"2022-11-21T14:59:10+00:00","description":"We can fetch a tweet given its tweet id using the get_tweet() method.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-ii\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg","width":1000,"height":563,"caption":"Python"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/7faa788f12ff54d5d598292f5a252fab","name":"Udisha Alok","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/udisha-alok\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/python-tile.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/162324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/731"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=162324"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/162324\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/83281"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=162324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=162324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=162324"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=162324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}