life is too short for a diary




Extract tweets from Twitter using Python

Tags: python

Author
Written by: Tushar Sharma
Featured image for Extract tweets from Twitter using Python
In this tutorial, we will extract tweets from Twitter using python.

First lets create a project-

We will use poetry for managing our dependencies.

We haven't implemented anything, so it will just ouput Get tweets for the tshrocks to the console. tshrocks is my twitter profile username

Next we need to authenticate with twitter, where we need access and consumer keys from twitter. You can go to developer page and create an app to get your keys.

Lastly, here's the full code.

We can get tweets by running

$ poetry run python get-tweets tshrocks
Get tweets for the tshrocks
getting tweets before 1284662084169596930
...389 tweets downloaded so far
getting tweets before 1030303523794288639
...571 tweets downloaded so far
getting tweets before 909242746770247681
...771 tweets downloaded so far
getting tweets before 312978397368291328
...963 tweets downloaded so far
getting tweets before 153814759517585407
...1157 tweets downloaded so far
getting tweets before 99546946154409983
...1177 tweets downloaded so far
getting tweets before 83587008219447295
...1177 tweets downloaded so far

We can open our csv file with any editor or excel.


comments powered by Disqus