{"id":160971,"date":"2022-10-10T11:52:36","date_gmt":"2022-10-10T15:52:36","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=160971"},"modified":"2022-11-21T09:58:56","modified_gmt":"2022-11-21T14:58:56","slug":"how-to-get-tweets-using-python-and-twitter-api-v2-part-i","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\/","title":{"rendered":"How to get Tweets using Python and Twitter API v2 &#8211; Part I"},"content":{"rendered":"\n<p>In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and how to deal with them, and get the local trends on Twitter.<\/p>\n\n\n\n<p>We will also look at the Client interface provided by the Tweepy library for the Twitter API v2 and how to work with it to get different types of data from Twitter.<\/p>\n\n\n\n<p>In the previous blog of this mini-series, we covered the methods available with the&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/python-twitter-api\/\">Twitter API v1<\/a>&nbsp;interface for getting different kinds of data from Twitter. We also looked at the types of access levels for the Twitter API.<\/p>\n\n\n\n<p>Here, we will cover the topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Premium search<br>&#8211; Search last 30 days<br>&#8211; Search the full archive<\/li><li>Rate limits<br>&#8211; How to check the rate limit status?<br>&#8211; How to set the app to wait till the rate limit is replenished?<\/li><li>Get trends for a location<\/li><li>Tweepy client for Twitter API v2<\/li><li>Client authentication<\/li><li>Get the user name for a particular user ID using client<\/li><li>Get the user ID for a particular user name using client<\/li><li>Get the user names for multiple user Ids using client<\/li><li>Get tweet(s) with tweet Id(s) using client<\/li><li>Get a user\u2019s followers using client<\/li><li>Get users that the user follows using client<\/li><li>Get a user\u2019s tweets using client<\/li><li>Get tweets that a user liked using client<\/li><li>Get users who retweeted a tweet using client<\/li><li>Search recent tweets using client<\/li><li>Get tweet count for a search query using client<\/li><li>Pagination in client<\/li><li>Using expansions to get user and media information<\/li><li>Writing the search results to a text file<\/li><li>Putting the search results into a dataframe<\/li><li>Twitter API v2 GitHub<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"premium-search\">Premium search<\/h3>\n\n\n\n<p>Premium search is a subscription API provided by Twitter. There are two products available with this API:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Search Tweets: 30-day endpoint<\/li><li>Search Tweets: Full-archive endpoint<\/li><\/ul>\n\n\n\n<p>To begin using any of the subscription APIs, you need to set up a dev environment&nbsp;<a href=\"https:\/\/developer.twitter.com\/en\/account\/environments\" target=\"_blank\" rel=\"noreferrer noopener\">\u207d\u00b9\u207e<\/a>&nbsp;for the endpoint.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"search-last-30-days\">Search last 30 days<\/h3>\n\n\n\n<p>Twitter provides the premium Search Tweets: 30-Day API, which gives you access to the tweets posted within the last 30 days. You can search over this database wherein tweets are matched against your query and returned.<\/p>\n\n\n\n<p>This feature can be accessed using the&nbsp;<strong>search_30_day<\/strong>() method of the API class.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Define the keywords for the query\nkeywords = \"stock market\"\nlimit = 300\n\n# We are now fetching only the tweets specifying the search criteria from the last 30 days\ntweets = tweepy.Cursor(api.search_30_day, label='test', query=keywords).items(limit)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/a1e0242b6f594c98fbe7adb4f34e8003#file-search_last_30_days-py\" target=\"_blank\" rel=\"noreferrer noopener\">search_last_30_days.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-the-full-archive\">Search the full archive<\/h3>\n\n\n\n<p>We can search the full archive using the&nbsp;<strong>search_full_archive<\/strong>() method. We can specify the dates and times from and to which we want to search the archive.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Define the keywords for the query\n# Tweets about Ethereum and excluding retweets\nkeywords = \"ethereum -RT\"\nlimit = 300\n\n# We are now fetching tweets specifying the search criteria in the archive\n# 'fromDate' must be in format 'yyyyMMddHHmm': we are fetching tweets from 20\/Aug\/2021 from midnight to noon\ntweets = tweepy.Cursor(api.search_full_archive, label='test', query=keywords, fromDate = '202108200000', toDate = '202108201200').items(limit)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/ec82d7246f566c82869e50013cb6b792#file-search_full_archive-py\" target=\"_blank\" rel=\"noreferrer noopener\">search_full_archive.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<h2 class=\"wp-block-heading\" id=\"rate-limits\">Rate limits<\/h2>\n\n\n\n<p>Twitter is an invaluable source of big data, accessed by millions of developers worldwide daily. It imposes utilization limits to make the API scalable and reliable. These limits on the usage depend on your authentication method.<\/p>\n\n\n\n<p>There are limits on the number of requests made in a specific time interval. These are called rate limits&nbsp;<a href=\"https:\/\/developer.twitter.com\/en\/docs\/twitter-api\/rate-limits\" target=\"_blank\" rel=\"noreferrer noopener\">\u207d\u00b2\u207e<\/a>.<\/p>\n\n\n\n<p><em>So how do we deal with these limits?<br>How will you know the status of the rate limit for you?<br>And what to do if your app breaches the rate limit?<br>Do you want it to terminate, or should it wait for the limit to get replenished?<\/em><\/p>\n\n\n\n<p>Let us explore these methods.<\/p>\n\n\n\n<p>How to check the rate limit status?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Check rate limit status\n# Calls to this method do not count against the rate limit\napi.rate_limit_status()<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/088d53a971be8c6f44fc0db7003910c7#file-check_limit_status-py\" target=\"_blank\" rel=\"noreferrer noopener\">check_limit_status.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>The&nbsp;<strong>api.rate_limit_status<\/strong>() method returns the available number of API requests for the user before the API limit is reached for the current hour. If you provide the credentials for a user, this method returns the rate limit status for this user. Else, it returns the rate limit status for the requester\u2019s IP address.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-set-the-app-to-wait-till-the-rate-limit-is-replenished\">How to set the App to wait till the rate limit Is replenished?<\/h3>\n\n\n\n<p>When we initialize the API class object after authentication, we can set it up so that it waits for the rate limits to get replenished.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>api = tweepy.API(auth, wait_on_rate_limit=True)\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/095807d2276151c62ad7c0b92ea84833#file-set_the_app-py\" target=\"_blank\" rel=\"noreferrer noopener\">set_the_app.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/095807d2276151c62ad7c0b92ea84833#file-set_the_app-py\" target=\"_blank\" rel=\"noreferrer noopener\">set_the_app.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<h2 class=\"wp-block-heading\" id=\"get-trends-for-a-location\">Get trends for a location<\/h2>\n\n\n\n<p>Trends are an important feature of Twitter. So how can we see which places are providing the trending topics currently?<\/p>\n\n\n\n<p>The available_trends() method returns the WOE (Where On Earth) id and other human-readable information for the locations for which Twitter has trending information.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>api.available_trends()<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/2278dbe1537ab695dbd327d5c6a99770#file-get_trends-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_trends.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>Let us now see how we can get the trending topics on Twitter for a particular location, be it a city or a country. For this, we need the WOE id of the location. You can get this from here&nbsp;<a href=\"https:\/\/www.woeids.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u207d\u00b3\u207e<\/a>.<\/p>\n\n\n\n<p>Once you have the WOE id of the place, getting the local trends is just a line of code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>woeid='1' # for  World\ntrends_world = api.get_place_trends(id = 1)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/7322acda2cbf3cb7a745e22799d5d6f5#file-place_trends-py\" target=\"_blank\" rel=\"noreferrer noopener\">place_trends.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<h2 class=\"wp-block-heading\" id=\"tweepy-client-for-twitter-api-v2\">Tweepy client for Twitter API v2<\/h2>\n\n\n\n<p>Tweepy provides the API interface for the Twitter API v1.1. For the v2 API, Tweepy provides the Client interface. This is available from Tweepy v4.0 onwards, so you may need to upgrade your&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/tweepy\/\">Tweepy<\/a>&nbsp;installation if you installed it a while back.<\/p>\n\n\n\n<p>You can do this by simply running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install tweepy \u2013upgrade\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"client-authentication\">Client authentication<\/h3>\n\n\n\n<p>Authentication is similar to API, except you need the bearer token for your project to authenticate the client.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>client = tweepy.Client(bearer_token=bearer_token, wait_on_rate_limit=True)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/e8302c8ed5b6370c8c4ddc7f3037db14#file-user_authentication-py\" target=\"_blank\" rel=\"noreferrer noopener\">user_authentication.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 the user name for a particular user ID using client<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># using get_user with id\nid = \"869660137\"\nuser = client.get_user(id=id)\nprint(f\"The user name for user id {id} is {user.data.name}.\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/5d04ddcd80f72de33a043864ccb72a55#file-get_user_name-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_user_name.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><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/5d04ddcd80f72de33a043864ccb72a55#file-get_user_name-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_user_name.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<p>Get the user ID for a particular user name using client<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># using get_user with user name\nusername = \"QuantInsti\"\nuser = client.get_user(username=username)\nprint(f\"The user name for user name {username} is {user.data.id}.\")<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/a812c462ff661b1265ffb195c8a50c89#file-get_user_id-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_user_id.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/a812c462ff661b1265ffb195c8a50c89#file-get_user_id-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_user_id.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-the-user-names-for-multiple-user-ids-using-client\">Get the user names for multiple user Ids using client<\/h3>\n\n\n\n<p>Let us now fetch the details for multiple user ids. We will fetch only some user fields&nbsp;<a href=\"https:\/\/developer.twitter.com\/en\/docs\/twitter-api\/data-dictionary\/object-model\/user\" target=\"_blank\" rel=\"noreferrer noopener\">\u207d\u2074\u207e<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># using get_users with multiple ids\nids = &#91;\"869660137\", \"21577803\", \"86813650\", \"44196397\"]\n# Fetch specific user fields\nusers = client.get_users(ids=ids, user_fields=&#91;\n                         'name', 'username', 'description'])\n\nfor user in users.data:\n    print(\n        f\"The user name for user id {user.id} is {user.username} and the name is {user.name}.\")\n    print(f\"'{user.description}'\\n\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/236fd949836d857dd844648efde6528d#file-get_multiple_user_names-py\" target=\"_blank\" rel=\"noreferrer noopener\">get_multiple_user_names.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>Using a similar approach, you can also try to fetch the user ids for multiple users. Try it out!<\/p>\n\n\n\n<p><em>Stay tuned for Part II to learn how to get Tweet(s) with Tweet Id(s) using client.<\/em><\/p>\n\n\n\n<p><em>Visit QuantInsti for additional insights on this topic: <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>In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and how to deal with them, and get the local trends on Twitter.<\/p>\n","protected":false},"author":731,"featured_media":132255,"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,12901,595,12900,12899,12357,12358],"contributors-categories":[13654],"class_list":{"0":"post-160971","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_trends-py","16":"tag-python","17":"tag-search_full_archive-py","18":"tag-search_last_30_days-py","19":"tag-tweepy","20":"tag-twitter-api","21":"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 &#8211; Part I<\/title>\n<meta name=\"description\" content=\"In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and...\" \/>\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\/160971\/\" \/>\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 - Part I | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and how to deal with them, and get the local trends on Twitter.\" \/>\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-i\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-10T15:52:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:58:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/04\/data-science-quant.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=\"6 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-i\\\/#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-i\\\/\"\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 &#8211; Part I\",\n\t            \"datePublished\": \"2022-10-10T15:52:36+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:58:56+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-i\\\/\"\n\t            },\n\t            \"wordCount\": 966,\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-i\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/data-science-quant.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"get_trends.py\",\n\t                \"Python\",\n\t                \"search_full_archive.py\",\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-i\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\\\/\",\n\t            \"name\": \"How to get Tweets using Python and Twitter API v2 - Part I | 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-i\\\/#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-i\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/data-science-quant.jpg\",\n\t            \"datePublished\": \"2022-10-10T15:52:36+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:58:56+00:00\",\n\t            \"description\": \"In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and how to deal with them, and get the local trends on Twitter.\",\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-i\\\/\"\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-i\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/data-science-quant.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/data-science-quant.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Data Science\"\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 &#8211; Part I","description":"In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and...","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\/160971\/","og_locale":"en_US","og_type":"article","og_title":"How to get Tweets using Python and Twitter API v2 - Part I | IBKR Quant Blog","og_description":"In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and how to deal with them, and get the local trends on Twitter.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\/","og_site_name":"IBKR Campus US","article_published_time":"2022-10-10T15:52:36+00:00","article_modified_time":"2022-11-21T14:58:56+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/04\/data-science-quant.jpg","type":"image\/jpeg"}],"author":"Udisha Alok","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Udisha Alok","Est. reading time":"6 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-i\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\/"},"author":{"name":"Udisha Alok","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/7faa788f12ff54d5d598292f5a252fab"},"headline":"How to get Tweets using Python and Twitter API v2 &#8211; Part I","datePublished":"2022-10-10T15:52:36+00:00","dateModified":"2022-11-21T14:58:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\/"},"wordCount":966,"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-i\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/04\/data-science-quant.jpg","keywords":["Data Science","get_trends.py","Python","search_full_archive.py","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-i\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\/","name":"How to get Tweets using Python and Twitter API v2 - Part I | 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-i\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-tweets-using-python-and-twitter-api-v2-part-i\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/04\/data-science-quant.jpg","datePublished":"2022-10-10T15:52:36+00:00","dateModified":"2022-11-21T14:58:56+00:00","description":"In this blog, we continue to explore the premium search features of the Twitter API using the API interface from Tweepy, check out the rate limits and how to deal with them, and get the local trends on Twitter.","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-i\/"]}]},{"@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-i\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/04\/data-science-quant.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/04\/data-science-quant.jpg","width":1000,"height":563,"caption":"Data Science"},{"@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\/2022\/04\/data-science-quant.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/160971","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=160971"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/160971\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/132255"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=160971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=160971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=160971"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=160971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}