Get UNLIMITED Tweets by Python Without Twitter API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we'll see how to get unlimited tweets without any authentication and we'll do this with just few lines of codes so since i made my first video on the twitter api two things happened first i cut my hair and second there were so many comments for the limitations of the api like we can only get 3200 user tweets or we can only get tweets that are seven days old today i'm excited to tell you that we're gonna solve these problems i show you how to get unlimited tweets without using the twitter api or any authentication we're going to do this with a python package called sn script so let's get started so let's start by installing the packages that we need so i open a new terminal and then i write pip install sn scrape so that's a package for social network scraping and then i do pip install pandas and then i will just use pandas to show the data and the twist that we are getting now i create a new python file call it twitch.pi so we start writing the code over there okay so first i do import sn modules that twitter as sn twitter and also import pandas as pd so now we have our modules then i write query equal to a string called python this is just for the beginning of writing the code and understanding how the tweet structure is and then later on we'll make this query much more complex so then i write for tweet in sn twitter dot twitter if i find it here twitter search scraper and then i pass over here the query and then we will use the get items method okay now let's just print the tweet and see how's the structure of it so i do print then i use the vars function to see all the attributes of this tweet and then pass over here to it and then let's just break the for loop now i write python tweets.pi so we should get one to it related to the query okay here it is so you see it has a lot of information over here like we have the url of the tweet the date of it its content which is the tweet and then we also have the information of the user if i find it here it is for example username it's id and so on so you can use all of this information for your tweets what i will do over here is to just for example consider tweets date user and content and convert it into a data frame so we see all these information together so i create an empty list call it tweets and then i also set the limit of the trees for example for now just a hundred okay then instead of printing the tweets what i will do if the length of tweets is equal to our limit it should be limit not limits if it's equal to limit i just break the loop if it's not i append it to my tweets list so i append all the information i want which is tweet that date tweet that user that user name and then tweet that content now i will make a data frame i use the pandas module create a data frame pass over here our tweets and also the name of the columns so i should set over here date the user and the tweets now let's just print this to it which is the data frame so let's see we should get a hundred tweets into a data frame and you see here they are so these are 100 tweets that we got related to our query but then the question is how we can make this search much more complex that is how we can get the tweets of a user how we can set the dates of the tweet that we want and this stuff so for this we should just change this query over here and to see how we can choose it let's go to twitter website so here is the twitter website and let's just search for something random like i just searched for python and then over here we see this advanced search click on it so we can over here set how we want to find tweets so as i said before from the twitter api we can only get 3200 tweets from a user what i will do is to get 5 000 tweets of elon musk from 2010 to 2020 so over here i'll go for from what account i'll put elon musk over here and then down here i choose from the january 1st 2010 to january 1st 2020 and then i hit search so now we have all the attributes for our search over here i just copy this text and then paste it into my python code so i paste it over here now i change also the limit to 5000 and run the code so this takes a bit of time based on what's the limit of the tweets like this might take for me like two minutes when i get all the data i will see the results over here so it took for me i guess like two minutes and now i have my five thousand tweets from elon musk you see we have two is 2019 2018 and the tweets are all over here so that's how we can get unlimited tweets without using the twitter api but then the question is what we can do with all of these tweets well one thing we can do is to do sentiment analysis that's why i made this video where i explain how to use the state-of-the-art model from the facebook ai team to do tweet sentiment analysis so make sure to check it out if this video was helpful please give it a thumbs up and subscribe thanks for watching and see you later
Info
Channel: AI Spectrum
Views: 64,153
Rating: undefined out of 5
Keywords: twitter api python, tweepy python
Id: jtIMnmbnOFo
Channel Id: undefined
Length: 7min 13sec (433 seconds)
Published: Tue Apr 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.