Created
January 27, 2026 10:15
-
-
Save cmj/1e2141c9fa678f301b2440fc0feecfe8 to your computer and use it in GitHub Desktop.
twikit GuestClient example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| from twikit.guest import GuestClient | |
| client = GuestClient() | |
| #client = GuestClient(proxy='http://127.0.0.1:8888') | |
| async def main(): | |
| # Activate the client by generating a guest token. | |
| guest_token = await client.activate() | |
| # Get user by screen name | |
| USER_SCREEN_NAME = 'nasa' | |
| user = await client.get_user_by_screen_name(USER_SCREEN_NAME) | |
| # Access user attributes | |
| print( | |
| f'id: {user.id}', | |
| f'name: {user.name}', | |
| f'followers: {user.followers_count}', | |
| f'tweets: {user.statuses_count}', | |
| '----', | |
| sep='\n' | |
| ) | |
| # Get tweet by ID | |
| # https://x.com/NASA/status/2014355402628939780 | |
| TWEET_ID = '2014355402628939780' | |
| tweet = await client.get_tweet_by_id(TWEET_ID) | |
| # Access tweet attributes | |
| print( | |
| f'id: {tweet.id}', | |
| f'text: {tweet.text}', | |
| f'likes: {tweet.favorite_count}', | |
| f'media: {tweet.media}', | |
| sep='\n' | |
| ) | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment