Get TWEETS by User and Hashtag with Python | Twitter API 2022

  Рет қаралды 35,793

AI Spectrum

AI Spectrum

Күн бұрын

Пікірлер: 111
@nitinluthra1751
@nitinluthra1751 2 жыл бұрын
A video specifically downloading and analyzing a large number of past tweets related to a specific hashtag would be very helpful.
@oreoluwadotun1785
@oreoluwadotun1785 2 жыл бұрын
Downloading then as Csv file
@tayalanjones8652
@tayalanjones8652 2 жыл бұрын
I love you, really. I need this methodology for my Ph.D. and you've saved my life. Really, Thank you!
@yakuzzo6355
@yakuzzo6355 2 жыл бұрын
perfect starting point into this fascinating sphere! 👌looking foreward to see deeper analysis of the data you scraped (maybe social network analysis or user sentiment analysis). 🙃
@ghofranhijazi6343
@ghofranhijazi6343 2 жыл бұрын
very useful. I am waiting for your next vedio.
@marvinlee9124
@marvinlee9124 2 жыл бұрын
Is there a way I can include 2 hashtags like : keyword = '#food' AND '#drink'? Or perhaps to get a specific location from a particular hashtag? Thanks :)
@mayuripandey415
@mayuripandey415 2 жыл бұрын
It was very helpful, but can you also make a video which states how to retrieve reply from a particular tweet, couldn't find such video on youtube..thanks
@jerrygcheng
@jerrygcheng 2 жыл бұрын
Brilliant! I would like to ask when we iterate the tweets object (in the line "for tweet in tweets"), it can easily reach the rate limit. How should we solve this problem?
@celianr1
@celianr1 Жыл бұрын
Thank you for the amazing videos with step by step guidance. Post the update of twitter api to 2.0, when i get the tweets, the retweets are truncated to 140 characters, can you suggest me a workaround
@ibrahimaba8966
@ibrahimaba8966 2 жыл бұрын
nice tutorial, i will apply some deep learning models such as sentiment analysis on this data! thank you!
@aispectrum
@aispectrum 2 жыл бұрын
I am really glad it was helpful!
@Nayrah-oi2hs
@Nayrah-oi2hs 2 жыл бұрын
Thanks for your Great Video!!! Just WoW !! I am really grateful to you 🤩
@nikolakalev4914
@nikolakalev4914 2 жыл бұрын
Thank you for the video!
@changez77654
@changez77654 2 жыл бұрын
Great video - thank you for sharing. Is there any way this method can be used to download all tweets of a user?
@vijayvenkatesh8328
@vijayvenkatesh8328 2 жыл бұрын
What can be the max value you can give for limit in tweets = tweepy.Cursor(.....).item(limit) ? ALso Can we add a since date and until date for this method?
@aispectrum
@aispectrum 2 жыл бұрын
Maximum number of tweets depends on the method you pass to Cursor. For api.user_timeline, the maximum is 3200, and for api.search_tweets I don't think there is any particular limit of number, but I know that you cannot get tweets older than 7-days. You can also add since and until dates, but again have on mind that you only can consider for the last 7-days. If you want for older than that, create 30-days dev environment, and then use api.search_30_day method.
@DroningJourneys
@DroningJourneys 2 жыл бұрын
Hi! great video, but how could I exclude all the retweets?
@vinayak254
@vinayak254 9 ай бұрын
can we search tweets in other language ?? do we have any option ?
@keerthi2141
@keerthi2141 2 жыл бұрын
Learning alot from ur videos.... Can u make a video explaining attributes of tweet, like city of the user, followers count, and all...
@ghislainniyongabo986
@ghislainniyongabo986 2 жыл бұрын
Hello, this is such an incredible video. Would it be possible to get tweets from a specific user with a particular hashtag? I would like to know if there is a method to combine one filter with user and hashtag. Thanks in advance for your reply.
@Chill-yv4gg
@Chill-yv4gg 2 жыл бұрын
Great video! I have a question about reading tweets. Do you need Elevated access in order to just read twitter id's off of twitter? Even if its tweets from a specific user?
@aispectrum
@aispectrum 2 жыл бұрын
Thanks! Actually you don't necessarily need elevated access. To do it, you can use the Client.get_user method to get the ids.
@Chill-yv4gg
@Chill-yv4gg 2 жыл бұрын
@@aispectrum Thank you lots! Additionally, when you u search tweets by keyword, how can you retrieve the usernames from the tweets?
@aispectrum
@aispectrum 2 жыл бұрын
@@Chill-yv4gg I think you can use tweet.user.screen_name for each tweet.
@mohammadismaylalmasud5399
@mohammadismaylalmasud5399 2 жыл бұрын
Thanks for the tutorial. Is it possible to gather historical all tweets with a specific hashtag (for example global warming) from 2000 to 2022? In other words, is there any limit to collecting the number of tweets for a specific hashtag ?......Thanks
@Noobffplay1
@Noobffplay1 Жыл бұрын
Sir kindly please tell the tool names in the starting so that students like me (new) can start easily. Thanks
@rohitray5947
@rohitray5947 Жыл бұрын
Can you develop a hashtag recommendation system for twitter in python using twitter datasets ?
@yichenguo3168
@yichenguo3168 2 жыл бұрын
Quick questions, how to get when is the tweets created for user timeline?
@J94_Film
@J94_Film 2 жыл бұрын
awesome video :) many thanks
@muhammadmudassar3825
@muhammadmudassar3825 2 жыл бұрын
excellent stuff for researchers and analysts but i have a problem i want to extract replies on tweet without using tweepy? how is it possible please save my time and help us
@geraldo.s5236
@geraldo.s5236 2 жыл бұрын
i'm having an issue with retrieving tweets with hashtags. the following error message showed up when i run the file. please help. Traceback (most recent call last): File "c:\Users\User\Documents\Tugas Akhir\analisis sentimen\twitter_data_users.py", line 50, in print(df) File "C:\Program Files\Python310\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 105-106: character maps to
@imranadilkhan
@imranadilkhan 2 жыл бұрын
very nice
@myrthezmind5157
@myrthezmind5157 2 жыл бұрын
Hello, thankyou so much for this video! Would it be possible to extract this data into csv using pandas?
@aispectrum
@aispectrum 2 жыл бұрын
Sure. try out "df.to_csv('tweets.csv', index = True)"
@myrthezmind5157
@myrthezmind5157 2 жыл бұрын
@@aispectrum thankyou!
@jonasschaf911
@jonasschaf911 Жыл бұрын
Would you consider this a web scraper? Since Twitter does not allow web scrapers.
@Francisco-dl1nb
@Francisco-dl1nb 2 жыл бұрын
As someone with no programming background trying to collect tweets and respective data for analysis, these videos have helped tremendously. When collecting tweets from a specific user, is there any way to only get tweets before a specific date (for ex, 100 tweets from user "X" before February 10th)? Thank you very much for your work!
@aispectrum
@aispectrum 2 жыл бұрын
Unfortunately it's not possible to directly filter user tweets based on dates. But what you could do it to get the tweet_id attribute of a tweet on the date that you want (like Feb. 10), then pass it to the function user_timeline as "max_id".
@axaana604
@axaana604 2 жыл бұрын
@@aispectrum How would that work if I want all tweets from let's say 2019 to 2020?
@aayushverma8173
@aayushverma8173 2 жыл бұрын
Really Helpful. Much appreciated. Would it be possible to extract these printed outputs into a csv or an excel document further and how? Thanks.
@kkrillz8971
@kkrillz8971 2 жыл бұрын
Can you create a similar one for Facebook especially on getting certain keywords
@sumitrathor9929
@sumitrathor9929 2 жыл бұрын
when we extract the names by tweet.user.name it is not the actual name of the user who tweeted on specific keywords the name is of a random person who retweeted. how to extract the name of actual person who tweeted?
@Revijeans
@Revijeans 2 жыл бұрын
Great video!! Thanks so much!! Quick question if I want to add the public_metrics (retweet count, reply count, like count and quote count) where should I add it? because I tried in the data.append but it says my attribute is empty... Could you help me with this? :) TIA!
@aispectrum
@aispectrum 2 жыл бұрын
In for tweet in tweets:, you should be able to get those attributes by, for example, writing tweet.retweet_count, tweet.favorite_count. I just tried it and could get access to those attributes.
@ahmedutuber
@ahmedutuber 2 жыл бұрын
absolutely you are 👌
@awkwardak4818
@awkwardak4818 2 жыл бұрын
Thanks the video is very helpful. Can you also tell me how can we get tweets from a specific user and containing a particular keyword? Or maybe after getting all the tweets from a specific user, how can we filter it so that it returns all tweets containing the keyword?
@aispectrum
@aispectrum 2 жыл бұрын
As you said it yourself, you can filter the results based on any keywords you like. You can try df[df['Tweet'].str.contains("hello")]
@awkwardak4818
@awkwardak4818 2 жыл бұрын
@@aispectrum Thank you. Is there a way to filter the results while calling the data from the api using tweepy.Cursor(). Because i wanted all 3000 tweets that are extracted should have those keywords.
@aispectrum
@aispectrum 2 жыл бұрын
@@awkwardak4818 Unfortunately I'm not aware of any other way. Specially because the API doesn't allow you to filter the tweets when calling the data.
@Marin-wz9ug
@Marin-wz9ug 2 жыл бұрын
Is there a way to scrape tweets from multiple users at once? Then, ideally being able to download them as a single CSV file? Thanks!
@aispectrum
@aispectrum 2 жыл бұрын
At the moment the only solution that comes to my mind is to loop over the uses and get their tweets, then append all the tweets to the data list, and make the dataframe. Then just simply save the dataframe into a csv file with the to_csv method.
@hemalshah1410
@hemalshah1410 Жыл бұрын
Hello, is the tweeter API still accessible for free ?
@jayyee3790
@jayyee3790 2 жыл бұрын
Thank you for this, was very helpful. The tweet_mode = 'extended' parameter is not working for me and I only return tweets up to 140 character in length, have you experienced this before?
@aispectrum
@aispectrum 2 жыл бұрын
Based on the tweepy's documentation, when you get the tweet from the full_text attribute, it should always return the full tweet. Are you getting the tweets from this attribute?
@jayyee3790
@jayyee3790 2 жыл бұрын
@@aispectrum Thank you for the reply! I am using the full_text attribute in addition to the tweet_mode = 'extended' parameter. Still not working.
@aispectrum
@aispectrum 2 жыл бұрын
@@jayyee3790 That’s odd. Frankly I cannot think of a solution for this unless maybe there’s a mistake in your code, or tweepy isn’t updated.
@Ore-rf1jq
@Ore-rf1jq 2 жыл бұрын
Struggling with how to download the tweets from the list so as to clean them
@jiaweifeng7160
@jiaweifeng7160 2 жыл бұрын
Thanks for your video! I learned a lot from it. However, I encountered a problem with the code. I did exactly as your video taught, but when trying to get data by user, the code "tweets = api.user_timeline(screen_name=user, count=limit, tweet_mode='extended')" return error 401 unauthorized. But I followed your instructions from your last video to get public_tweets, it worked perfectly. Are there any solutions about the error? Thank you very much!
@faqapour6166
@faqapour6166 2 жыл бұрын
what is the name of your platform that coding in it?
@aispectrum
@aispectrum 2 жыл бұрын
Visual studio code is one of the best
@arik20z
@arik20z 2 жыл бұрын
Hola, como seria el caso de querer buscar Tweets que mencionen un Hashtag? y no por usuario. Gracias
@Neurofilia
@Neurofilia 2 жыл бұрын
En el apartado de q='#tuhashtag'
@roberttyler2861
@roberttyler2861 2 жыл бұрын
Why would we use the API1.1 interface and not 2 from tweepy?
@aispectrum
@aispectrum 2 жыл бұрын
I wouldn't say you should only use one. It is recommended to use v2 if you can. But if there are methods that are only available with v1.1, then you wouldn't have other option.
@Evelinanca
@Evelinanca 2 жыл бұрын
Hi, thank you for the video, but there are two things I don't understand. I played around and searched for different hashtags and I'm getting results but the one hashtag I need says 'Empty data frame' while 100% this hashtag is used on twitter. Really weird! Also how would you request a date for each tweets? (ay, month, year) and country? I entered 'tweet.date' and 'tweet.country' but its not identifying it. Please help :(
@aispectrum
@aispectrum 2 жыл бұрын
Unfortunately I don't have a solution for the first questions. But for the second one, you can pass for example until="2022-03-19" to get tweets older than this date(just remember that you can only get 7-days old tweets). Another way is to pass since_id to get older tweets or max_id to get tweets more recent tweets. For country, try the geocode parameter to give the location of the users (pass latitude,longitude,radius)
@Restlesscrocodile
@Restlesscrocodile 2 жыл бұрын
Hi Daniela, I think you mean you'd like the date as a column next to each tweet? I found a way to do this by copying the 1st video from this channel, where he requests three columns, time, user and tweet text - and changing this from the two columns requested here.
@goutamb2411
@goutamb2411 2 жыл бұрын
How to pass both user name and keywords together to get the tweets posted by specific user containing a particular list of keywords?
@fuadarbiansyah8401
@fuadarbiansyah8401 2 жыл бұрын
You can do by change the keyword variable to : keywords = 'from:username keywordYouWantToSearch'
@6amjad
@6amjad 2 жыл бұрын
Can we search for multiple keywords at the same time ? like (username + good ) and how can do this
@aispectrum
@aispectrum 2 жыл бұрын
This possible by writing the search the query as “Word (from:Username)”. You can even use advanced search of twitter website to search for more complex criteria.
@navinpatwari4056
@navinpatwari4056 Жыл бұрын
after introduction to version 2, this one seems not to work
@mohammedmo97
@mohammedmo97 2 жыл бұрын
how do you extract hashtags from a specific user, eg say i want to extract elon musks tweets on #dogecoin only, it would be great if you could help, Great Video.
@aispectrum
@aispectrum 2 жыл бұрын
I think it's better that you get the tweets of the user that you want. Then just filter based on the keyword that you want.
@张恒-f8v
@张恒-f8v 2 жыл бұрын
how can i scrape the data earlier? tweepy using api merely get data last 7 days
@aispectrum
@aispectrum 2 жыл бұрын
If you want get tweets older than 7 days, create a 30-days dev environment on twitter developer website, and then use api.search_30_day method in the python code.
@yhk6187
@yhk6187 2 жыл бұрын
When i try to export this to excel, following error occurs: ValueError: Excel does not support datetimes with timezones. Please ensure that datetimes are timezone unaware before writing to Excel. Is there any good way to treat date data from your tutorial codes?
@aispectrum
@aispectrum 2 жыл бұрын
Have you tried df.to_csv() instead?
@lisanneburghardt1746
@lisanneburghardt1746 2 жыл бұрын
Great video and explanation! But whenever I try to execute your script I get the error "tweepy.errors.BadRequest: 400 Bad Request 215 - Bad Authentication data." even though I have elevated access to the Twitter API and have used simpler scripts for Tweepy before that worked well. Does anyone know what might be the issue?
@aispectrum
@aispectrum 2 жыл бұрын
The most common solution to this problem is regenerating API keys and access tokens. Also just in case, make sure that you are using the latest version of tweepy.
@lisanneburghardt1746
@lisanneburghardt1746 2 жыл бұрын
@@aispectrum Thank you for the super quick reply. Unfortunately my API Keys and access token work if I run other scripts and I do have the latest version of tweepy 😕
@aispectrum
@aispectrum 2 жыл бұрын
@@lisanneburghardt1746 See if this helps: github.com/duttashi/scrapers/issues/21
@lincolnluther3019
@lincolnluther3019 Жыл бұрын
I get same issue as well, any solution to this ?
@easieee24
@easieee24 2 жыл бұрын
how you can get tweets from the year 2020 to the year 2022
@kkrillz8971
@kkrillz8971 2 жыл бұрын
By searching keywords,, how can I get the number of follwers of the people who tweeted the keywords searched
@aispectrum
@aispectrum 2 жыл бұрын
You can pass the username of each account to api.get_followers to get the followers.
@peggyleung6765
@peggyleung6765 2 жыл бұрын
hi! I try to code and there is an error msg showing "Unauthorized: 401 Unauthorized" in "for tweet in tweets: data.append([tweet.user.screen_name, tweet.full_text])" How can I fix it? Thanks !
@aispectrum
@aispectrum 2 жыл бұрын
This error is related to the credentials of your account. Double check your api keys, and if they are correct, the app should connect to the API with no problem.
@easycode4093
@easycode4093 2 жыл бұрын
Good
@visantos9286
@visantos9286 2 жыл бұрын
The following error occurs: PS C:\Users\Usuário> & C:/ProgramData/Anaconda3/python.exe c:/Users/Usuário/Desktop/tweepy_tests/twitter_data_users.py Traceback (most recent call last): File "c:\Users\Usuário\Desktop\tweepy_tests\twitter_data_users.py", line 9, in api_key = config['twitter']['api_key'] File "C:\ProgramData\Anaconda3\lib\configparser.py", line 963, in __getitem__ raise KeyError(key) I also tried to move the config and twitter_data files to the same path as 'configparser.py', but the error continues. Would you know how to solve it, please?
@aispectrum
@aispectrum 2 жыл бұрын
This is because the python code cannot find the config file. Make sure that the files are in the same directory, and it should solve the issue. If didn't, the easiest option is to just directly put your keys in the python file. Something like api_key = "paste the key here"
@ekhnio
@ekhnio 2 жыл бұрын
Bro please make a video on “How to use Twitter developer account for beginners or differences between normal Twitter and Twitter developer” 🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻🤟🏻
@outsideclassroom5446
@outsideclassroom5446 2 жыл бұрын
How old tweets can we extract using this code
@aispectrum
@aispectrum 2 жыл бұрын
For the search method, there is a 7-day limit. So you cannot get tweets older than a week. There is also a 30-day search limit that you can use. For this, you should create a dev environment on the twitter developer website for "search tweets: 30-day". Then in you program, use search_30_day method. If you want older results, you should apply for Academic Research access on the twitter developer website, and then use search_full_archive method.
@agam6057
@agam6057 2 жыл бұрын
@@aispectrum Is there any way to get the older tweets without academic research access?
@aispectrum
@aispectrum 2 жыл бұрын
@@agam6057 I don't think there is another way. As far as I know to get access to the full tweet archive Twitter requires you to be a student or part of an academic institution.
@rx_lang
@rx_lang 2 жыл бұрын
@@aispectrum Thank you for explaining, it's very useful for me
@enockjr5048
@enockjr5048 2 жыл бұрын
i cannot use tweepy, i write and nothiung happens in 'import tweepy'
@aispectrum
@aispectrum 2 жыл бұрын
Do you mean that you only write “import tweepy” and nothing happens? Have you installed tweepy using pip install tweepy
@enockjr5048
@enockjr5048 2 жыл бұрын
@@aispectrum yup, now i install tweepy in cmd
@devkolsawla6701
@devkolsawla6701 2 жыл бұрын
Getting error like this KeyError: 'twitter' Any suggestions how to solve this
@aispectrum
@aispectrum 2 жыл бұрын
It's not clear why you are getting this error. There should be more information in the console that can be helpful to find the solution.
@AEG_UK2020
@AEG_UK2020 2 жыл бұрын
@@aispectrum it would be helpful to understand "twitter" within the logic?
@robinreliant3245
@robinreliant3245 2 жыл бұрын
anyone knows why he can get 100 queries but when I do it I only got 20 queries max? *edit Nvm, i followed the video and it works. And I think theres a limit for 1500 tweets that i read from somewhere
@_peetza
@_peetza Жыл бұрын
Zoom out. Ffs.
@Malak-jt5oj
@Malak-jt5oj 2 жыл бұрын
Can i have ur email 🙏🏻
@AEG_UK2020
@AEG_UK2020 2 жыл бұрын
I tried this; it's stuck at api_key = config['twitter']['api_key'] error of line 964, in __getitem__ raise KeyError(key) KeyError: 'twitter'
@aispectrum
@aispectrum 2 жыл бұрын
Is your config file in the same folder of the python code? If not, that could be the cause of this error. Other than, you can directly type the credentials in the python file, something like api_key = "xxxxxxxxxxx"
@ArowanaNFTs
@ArowanaNFTs 2 жыл бұрын
query = "(#alcnft) (from:Thla1oc)" - this thing didn't work, though I have use this hashtag often
@aliaformo9487
@aliaformo9487 Жыл бұрын
Great video! Thank you
How to Get Real-time Tweets by Python
9:04
AI Spectrum
Рет қаралды 18 М.
How I get Tweet data for FREE in 2024 as a data scientist
19:28
AI Spectrum
Рет қаралды 22 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
How to Extract Data from Twitter using Python [Tweepy API]
5:40
Analytics with Adam
Рет қаралды 80 М.
How to get TWEETS by Python | Twitter API 2022
17:04
AI Spectrum
Рет қаралды 147 М.
Some tricks with UV and a new Python project: uvtrick!
11:45
CalmCode
Рет қаралды 13 М.
Get UNLIMITED Tweets by Python Without Twitter API
7:13
AI Spectrum
Рет қаралды 107 М.
I scraped Andrew Tate Twitter Profile using Python
13:06
TopNotch Programmer
Рет қаралды 2,9 М.
Scrape Tweets with No Limitation and No API Key with Twint
10:18
Ahmed Besbes
Рет қаралды 50 М.
ASMR Programming - Spinning Cube - No Talking
20:45
Servet Gulnaroglu
Рет қаралды 4,3 МЛН
Create Stunning Python GUIs in 10 Minutes With Drag & Drop
11:38
Coding Is Fun
Рет қаралды 107 М.
Scrape Twitter with 5 Lines of Code
6:36
Rob Mulla
Рет қаралды 76 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН