Skip to content

Info: Twitter API v2 Sample Code

Matthew R. DeVerna edited this page Aug 1, 2021 · 3 revisions

Twitter has been kind enough to illustrate the usage of different endpoints. If you're not a fan of the osometweet package and would like to work with these endpoints directly, you can find sample code on GitHub by following the link below:

Direct Links to Python Code:

Endpoint Code Sample
Blocks Lookup Code
Block a User Code
Unblock a User Code
Followers Lookup Code
Following Lookup Code
Search (Full Archive) Code
Search (Recent) Code
Likes Lookup (tweets) Code
Likes Lookup (users) Code
Like a Tweet Code
Unlike a Tweet Code
Mute a User Code
Unmute a User Code
Retweet a Tweet Code
Undo a Retweet Code
Retweets Lookup Code
Stream (Sampled) Code
Stream (Filtered) Code
Get Tweets (Bearer Token) Code
Get Tweets (User Tokens) Code
Get Users (Bearer Token) Code
Get Users (User Tokens) Code
Tweet Counts (Full Archive) Code
Tweet Counts (Recent) Code
User Mention Timeline Code
User Tweet Timeline Code

Let's try and keep this updated if we can. For example, there is an outstanding issue on the Twitter v2 GitHub Repo which aims to provide some type of code sample that discusses or implements reconnections for the streaming endpoints. Keeping up on this type of information will be helpful if Twitter continues to address these issues.

Last Updated: Aug. 1, 2020