DEV Community

A comprehensive guide for using the Twitter API v2 with Tweepy in Python

Suhem Parack on September 29, 2021

Tweepy is a popular package in Python used by students, researchers and developers for interacting with the Twitter API. Recently, the version 4.0 ...
Collapse
 
alanstocco profile image
Alan Stocco

Great tutorial. Thanks. I have to do something similar.
I have to extract both retweet and comments/replies done by a specific user in input(or list) in a specific page/user that contains a specific hashtag.
For retweet no problem. For comments some

Collapse
 
y3khan profile image
Yasser Khan

great tutorial. I am glad you used tweepy to show the functionalities! Thank You

Few notes:

  • I was not able to execute some statements because I do not have access to the academic research account
  • I was not able to complete # 9. Getting Tweet counts (volume) for a search query because It says , "unexpected parameter: granularity".
Collapse
 
jwang14247372 profile image
J Wang

Great tutorial.

Collapse
 
mikkel_thomhav_6b720a53a7 profile image
Mikkel Thomhav

Hey man. Thank you so much for this article.
I was stuck with a problem for 7 days, but it's solved now.
I still have one small problem though, and i think you can help me out.
Is there any ways to contact you? Would you mind adding me on telegram?
Username: everydaypsychologies

or write me an email at: mikkelthomav@gmail.com

Best regards
Mikkel

Collapse
 
mble profile image
Maciej Błędkowski

I get this error and I have no idea why, in other project that uses Twitter API v1 every works fine:
tweepy.errors.Unauthorized: 401 Unauthorized

Collapse
 
bserjeantson profile image
Brett Serjeantson

So I have streaming working for V2. However, it seems that the only data I can get for the author of the incoming tweets is the author_id.

Does this mean I have to do a separate user lookup to get username, description, etc... using the following?

users = client.get_users(ids=idarray, user_fields=fieldarray)

Also, I see there is an allowance of 900 calls per 15 minutes. However, when I run the following function, 'data = api.rate_limit_status()', I can't see any of my calls being decremented.

Thoughts?

Collapse
 
zeguil profile image
José Guilherme

two questions:
1 - How can I reply to tweets?
2 - How can I tweet an image?

Collapse
 
taotetom profile image
TaoTeTom

Question:

If I want to search for a given topic or for tweets that have above x likes how would I do that?

Thanks this guide has been uber helpful

Collapse
 
goldytech profile image
Muhammad Afzal Qureshi

Thanks for the great post. How can I retrieve all the replies for a given tweet ?

Collapse
 
srisai1796 profile image
Sri_Sai

Hey, This is really helpful. Is there any update on Filtered Stream in Python in a similar way ? @TwitterDev

Collapse
 
szyle profile image
szyle

i needed this. thank you.

Collapse
 
thalibarrifqi profile image
gray november, hey december

How to add language filter when using pagination?

Collapse
 
kiprono profile image
Kiprono

Hey @suhemparack How can I tweet an image?