### Install Twikit via pip Source: https://github.com/d60/twikit/blob/main/README.md Use this command to install the library in your environment. ```bash pip install twikit ``` -------------------------------- ### Set Up and Process Real-time Streaming Events Source: https://github.com/d60/twikit/blob/main/docs/twikit.md This example demonstrates how to set up a streaming session with specific topics and process incoming payloads for DM updates, DM typings, and tweet engagements. Ensure you have a client instance and necessary topics defined. ```python from twikit.streaming import Topic topics = { Topic.tweet_engagement('1739617652'), # Stream tweet engagement Topic.dm_update('17544932482-174455537996'), # Stream DM update Topic.dm_typing('17544932482-174455537996') # Stream DM typing } session = client.get_streaming_session(topics) for topic, payload in session: if payload.dm_update: conversation_id = payload.dm_update.conversation_id user_id = payload.dm_update.user_id print(f'{conversation_id}: {user_id} sent a message') if payload.dm_typing: conversation_id = payload.dm_typing.conversation_id user_id = payload.dm_typing.user_id print(f'{conversation_id}: {user_id} is typing') if payload.tweet_engagement: like = payload.tweet_engagement.like_count retweet = payload.tweet_engagement.retweet_count view = payload.tweet_engagement.view_count print(f'Tweet engagement updated likes: {like} retweets: {retweet} views: {view}') ``` -------------------------------- ### GET /get_place Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches details for a specific place by ID. ```APIDOC ## GET /get_place ### Description Fetches a place by ID. ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the place. ### Response #### Success Response (200) - **place** (Place) - The Place object. ``` -------------------------------- ### Get Bookmark Folders Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves all bookmark folders created by the user. Supports pagination using the `next()` method. ```python >>> folders = await client.get_bookmark_folders() >>> print(folders) [, ..., ] >>> more_folders = await folders.next() # Retrieve more folders ``` -------------------------------- ### Get Followers and Following Source: https://context7.com/d60/twikit/llms.txt Retrieve lists of followers or followed accounts, with support for pagination and ID-only retrieval. ```python async def followers_following_example(): user = await client.get_user_by_screen_name('twitter') # Get followers followers = await client.get_user_followers(user.id, count=20) for follower in followers: print(f"@{follower.screen_name}: {follower.followers_count} followers") # Get more followers more_followers = await followers.next() # Get following (accounts the user follows) following = await client.get_user_following(user.id, count=20) for account in following: print(f"Following: @{account.screen_name}") # Get follower IDs only (faster for large counts) follower_ids = await client.get_followers_ids(user_id=user.id, count=5000) print(f"Total follower IDs: {len(follower_ids)}") ``` -------------------------------- ### GET /communities/{community_id} Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a community by its ID. ```APIDOC ## GET /communities/{community_id} ### Description Retrieves community by ID. ### Method GET ### Endpoint /communities/{community_id} ### Parameters #### Path Parameters - **community_id** (string) - Required - The ID of the community to retrieve. ### Response #### Success Response (200) - **Community** (object) - The community object. - **id** (string) - The ID of the community. ### Response Example ```json { "id": "..." } ``` ``` -------------------------------- ### GET User Followers Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of followers for the user. ```APIDOC ## GET get_followers ### Description Retrieves a list of followers for the user. ### Parameters #### Query Parameters - **count** (int) - Optional - The number of followers to retrieve (default=20). ### Response #### Success Response (200) - **Result** (Result[User]) - A list of User objects representing the followers. ``` -------------------------------- ### GET /get_timeline Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves the 'For You' timeline for the authenticated user. ```APIDOC ## GET /get_timeline ### Description Retrieves tweets from Home -> For You. ### Parameters #### Query Parameters - **count** (int) - Optional - Number of tweets to retrieve (default 20). - **seen_tweet_ids** (list[str]) - Optional - List of seen tweet IDs. - **cursor** (str) - Optional - Pagination cursor. ``` -------------------------------- ### GET /get_user_by_screen_name Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches a user profile by their screen name. ```APIDOC ## GET /get_user_by_screen_name ### Description Fetches a user by screen name. ### Parameters #### Query Parameters - **screen_name** (str) - Required - The screen name of the Twitter user. ### Response #### Success Response (200) - **user** (User) - An instance of the User class representing the Twitter user. ``` -------------------------------- ### Update Streaming Session Subscriptions Source: https://github.com/d60/twikit/blob/main/docs/twikit.md This example shows how to update the topics subscribed to in an existing streaming session. You can specify topics to subscribe to and topics to unsubscribe from. Note that 'dm_update' and 'dm_typing' cannot be added. ```python from twikit.streaming import Topic subscribe_topics = { Topic.tweet_engagement('1749528513'), Topic.tweet_engagement('1765829534') } unsubscribe_topics = { Topic.tweet_engagement('17396176529'), Topic.dm_update('17544932482-174455537996'), Topic.dm_typing('17544932482-174455537996)' } await session.update_subscriptions( subscribe_topics, unsubscribe_topics ) ``` -------------------------------- ### GET /get_lists Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a collection of lists associated with the user. ```APIDOC ## GET /get_lists ### Description Retrieves a list of user lists. ### Parameters #### Query Parameters - **count** (int) - Optional - The number of lists to retrieve (default 100). - **cursor** (str) - Optional - The cursor for pagination. ### Response - **Result[List]** (object) - Retrieved lists. ``` -------------------------------- ### GET /get_list Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves details for a specific list by its ID. ```APIDOC ## GET /get_list ### Description Retrieve list by ID. ### Parameters #### Query Parameters - **list_id** (str) - Required - The ID of the list to retrieve. ### Response - **List** (object) - List object. ``` -------------------------------- ### Get More Bookmarks Source: https://github.com/d60/twikit/blob/main/docs/twikit.md If there are more bookmarks than initially retrieved, use the `next()` method on the result object to fetch additional bookmarks. ```python >>> # # To retrieve more bookmarks >>> more_bookmarks = await bookmarks.next() >>> for bookmark in more_bookmarks: ... print(bookmark) ``` -------------------------------- ### GET /bookmarks Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of bookmarks from the authenticated user's account. ```APIDOC ## GET /bookmarks ### Description Retrieves bookmarks from the authenticated user’s Twitter account. ### Parameters #### Query Parameters - **count** (int) - Optional - The number of bookmarks to retrieve (default: 20). - **cursor** (str) - Optional - Cursor for pagination. - **folder_id** (str) - Optional - Folder to retrieve bookmarks from. ### Response #### Success Response (200) - **Result[Tweet]** (object) - A Result object containing a list of Tweet objects. ``` -------------------------------- ### Download Video from Tweet Media Source: https://github.com/d60/twikit/blob/main/docs/twikit.md This example demonstrates how to download a video from a tweet's media. It first retrieves a tweet by its ID, accesses the first media object, and then downloads the first available stream of the video. ```python # Video download example tweet = await client.get_tweet_by_id('00000000000') video = tweet.media[0] streams = video.streams await streams[0].download('output.mp4') ``` -------------------------------- ### Get User Following Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of users that a given user is following. The 'count' parameter specifies the number of users to fetch per request. Results are returned as a `Result` object containing `User` objects. ```python >>> await client.get_user_following(user_id='12345') >>> await client.get_user_following(user_id='12345', count=50) ``` -------------------------------- ### GET /users/:user_id/following Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of users whom the given user is following. ```APIDOC ## GET /users/:user_id/following ### Description Retrieves a list of users whom the given user is following. ### Method GET ### Endpoint /users/{user_id}/following ### Parameters #### Path Parameters - **user_id** (string) - Required - The ID of the user for whom to retrieve the following users. #### Query Parameters - **count** (integer) - Optional - The number of following users to retrieve. Defaults to 20. - **cursor** (string) - Optional - Used for pagination. ### Response #### Success Response (200) - **following** (Result[User]) - A Result object containing a list of User objects representing the users being followed. ### Response Example ```json { "following": { "users": [ { "id": "99999", "screen_name": "followed_user1" }, { "id": "10101", "screen_name": "followed_user2" } ], "next_cursor": "next_cursor_string" } } ``` ``` -------------------------------- ### Get User Subscriptions Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of users to whom the specified user is subscribed. The 'count' parameter determines the number of subscriptions to fetch. Results are returned as a `Result` object containing `User` objects. ```python >>> await client.get_user_subscriptions(user_id='12345') >>> await client.get_user_subscriptions(user_id='12345', count=50) ``` -------------------------------- ### Retrieve and Iterate Video Subtitles Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches subtitles for a video and iterates through the start time, end time, and text content of each subtitle entry. ```python tweet = await client.get_tweet_by_id('00000000000') video = tweet.media[0] subtitles = await video.get_subtitles() for l in subtitles: print(l.start) print(l.end) print(l.text) ``` -------------------------------- ### Get Place Trends by WOEID Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches the top 50 trending topics for a specific geographical location identified by its WOEID (Where On Earth ID). Use `Client.get_available_locations()` to find the WOEID for a desired location. ```python >>> await client.get_place_trends(woeid=1) ``` -------------------------------- ### GET /trends/place/:woeid Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves the top 50 trending topics for a specific location identified by its WOEID. ```APIDOC ## GET /trends/place/:woeid ### Description Retrieves the top 50 trending topics for a specific id. ### Method GET ### Endpoint /trends/place/{woeid} ### Parameters #### Path Parameters - **woeid** (integer) - Required - The Where On Earth ID (WOEID) of the location for which to retrieve trends. ### Response #### Success Response (200) - **trends** (PlaceTrends) - A PlaceTrends object containing the top 50 trending topics for the specified location. ### Response Example ```json { "trends": [ { "name": "Example Place Trend 1" }, { "name": "Example Place Trend 2" } ] } ``` ``` -------------------------------- ### GET /communities/timeline Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves tweets from the communities timeline. ```APIDOC ## GET /communities/timeline ### Description Retrieves tweets from communities timeline. ### Method GET ### Endpoint /communities/timeline ### Parameters #### Query Parameters - **count** (integer) - Optional - The number of tweets to retrieve. Defaults to 20. - **cursor** (string) - Optional - Cursor for pagination. ### Response #### Success Response (200) - **Result** (object) - Contains a list of Tweet objects. - **tweets** (array) - List of Tweet objects. - **id** (string) - The ID of the tweet. ### Request Example ```python tweets = await client.get_communities_timeline() ``` ### Response Example ```json { "tweets": [ { "id": "..." }, { "id": "..." } ] } ``` ``` -------------------------------- ### Initialize Client and Login Source: https://github.com/d60/twikit/blob/main/README.md Set up the Twikit client and authenticate using credentials and a cookies file. ```python import asyncio from twikit import Client USERNAME = 'example_user' EMAIL = 'email@example.com' PASSWORD = 'password0000' # Initialize client client = Client('en-US') async def main(): await client.login( auth_info_1=USERNAME, auth_info_2=EMAIL, password=PASSWORD, cookies_file='cookies.json' ) asyncio.run(main()) ``` -------------------------------- ### Configure Proxy Servers Source: https://context7.com/d60/twikit/llms.txt Set up HTTP or SOCKS5 proxies during client initialization or update them dynamically. ```python # HTTP proxy client = Client('en-US', proxy='http://proxy.example.com:8080') # SOCKS5 proxy client = Client('en-US', proxy='socks5://user:pass@proxy.example.com:1080') # Change proxy after initialization client.proxy = 'http://new-proxy.example.com:8080' ``` -------------------------------- ### Get User ID from Screen Name Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Use this when you only have the screen name and need to retrieve the corresponding user ID. ```python >>> screen_name = 'example_user' >>> user = client.get_user_by_screen_name(screen_name) >>> user_id = user.id ``` -------------------------------- ### GET /get_list_subscribers Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves the subscribers of a specific list. ```APIDOC ## GET /get_list_subscribers ### Description Retrieves subscribers of a list. ### Parameters #### Query Parameters - **list_id** (str) - Required - List ID. - **count** (int) - Optional - Number of subscribers to retrieve (default 20). - **cursor** (str) - Optional - The cursor for pagination. ### Response - **Result[User]** (object) - Subscribers of a list. ``` -------------------------------- ### Manage Streaming Sessions and Subscriptions Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Demonstrates how to initialize a streaming session with specific topics and update subscriptions dynamically. ```pycon >>> from twikit.streaming import Topic >>> >>> topics = { ... Topic.tweet_engagement('1739617652'), # Stream tweet engagement ... Topic.dm_update('17544932482-174455537996'), # Stream DM update ... Topic.dm_typing('17544932482-174455537996') # Stream DM typing ... } >>> session = await client.get_streaming_session(topics) >>> >>> async for topic, payload in session: ... if payload.dm_update: ... conversation_id = payload.dm_update.conversation_id ... user_id = payload.dm_update.user_id ... print(f'{conversation_id}: {user_id} sent a message') >>> >>> if payload.dm_typing: ... conversation_id = payload.dm_typing.conversation_id ... user_id = payload.dm_typing.user_id ... print(f'{conversation_id}: {user_id} is typing') >>> >>> if payload.tweet_engagement: ... like = payload.tweet_engagement.like_count ... retweet = payload.tweet_engagement.retweet_count ... view = payload.tweet_engagement.view_count ... print('Tweet engagement updated:' ... f'likes: {like} retweets: {retweet} views: {view}') ``` ```pycon >>> subscribe_topics = { ... Topic.tweet_engagement('1749528513'), ... Topic.tweet_engagement('1765829534') ... } >>> unsubscribe_topics = { ... Topic.tweet_engagement('1739617652'), ... Topic.dm_update('17544932482-174455537996'), ... Topic.dm_update('17544932482-174455537996') ... } >>> await session.update_subscriptions( ... subscribe_topics, unsubscribe_topics ... ) ``` -------------------------------- ### Get Bookmarks Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves bookmarks from the authenticated user's Twitter account. Can specify count and folder ID. ```python >>> bookmarks = await client.get_bookmarks() >>> for bookmark in bookmarks: ... print(bookmark) ``` -------------------------------- ### Login with Authentication Details Source: https://github.com/d60/twikit/blob/main/ToProtectYourAccount.md Use this method for the initial login. Ensure you have the correct authentication information. ```python client.login( auth_info_1='...', auth_info_2='...', password='...' ) ``` -------------------------------- ### GET /get_list_members Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves the members of a specific list. ```APIDOC ## GET /get_list_members ### Description Retrieves members of a list. ### Parameters #### Query Parameters - **list_id** (str) - Required - List ID. - **count** (int) - Optional - Number of members to retrieve (default 20). - **cursor** (str) - Optional - The cursor for pagination. ### Response - **Result[User]** (object) - Members of a list. ``` -------------------------------- ### Get Follower IDs Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches a list of follower IDs for a given user. Supports fetching by user ID or screen name, with options for count and cursor. ```python # Fetches follower IDs for a user # user_id or screen_name must be provided # Example usage would involve calling this method with appropriate parameters. ``` -------------------------------- ### GET /users/latest_followers Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves the latest followers for a user. ```APIDOC ## GET /users/latest_followers ### Description Retrieves the latest followers. ### Method GET ### Endpoint /users/latest_followers ### Parameters #### Query Parameters - **user_id** (string) - Optional - The ID of the user for whom to retrieve followers. - **screen_name** (string) - Optional - The screen name of the user for whom to retrieve followers. - **count** (integer) - Optional - The number of followers to retrieve. Max count is 200. Defaults to 200. - **cursor** (string) - Optional - Used for pagination. ### Response #### Success Response (200) - **followers** (Result[User]) - A Result object containing a list of User objects representing the latest followers. ### Response Example ```json { "followers": { "users": [ { "id": "11111", "screen_name": "latest_user1" }, { "id": "22222", "screen_name": "latest_user2" } ], "next_cursor": "next_cursor_string" } } ``` ``` -------------------------------- ### Get Verified Followers Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of verified followers for a given user ID. The 'count' parameter determines the number of verified followers to fetch. Results are returned as a `Result` object containing `User` objects. ```python >>> await client.get_user_verified_followers(user_id='12345') >>> await client.get_user_verified_followers(user_id='12345', count=50) ``` -------------------------------- ### Create Bookmark Folder Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Creates a new bookmark folder with the specified name. ```python >>> await client.create_bookmark_folder('NewFolderName') ``` -------------------------------- ### GET /search_geo Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Search for places that can be attached to a Tweet. ```APIDOC ## GET /search_geo ### Description Search for places that can be attached to a Tweet via POST statuses/update. ### Parameters #### Query Parameters - **lat** (float) - Optional - The latitude to search around. - **long** (float) - Optional - The longitude to search around. - **query** (str) - Optional - Free-form text to match against. - **ip** (str) - Optional - An IP address. - **granularity** (str) - Optional - Minimal granularity of place types. - **max_results** (int) - Optional - A hint as to the number of results to return. ### Response #### Success Response (200) - **places** (list[Place]) - A list of Place objects. ``` -------------------------------- ### Initialize Twikit Client Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Create a new instance of the Client class with a specified language. ```pycon >>> client = Client(language='en-US') ``` -------------------------------- ### GET /communities/{community_id}/members Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves members of a community. ```APIDOC ## GET /communities/{community_id}/members ### Description Retrieves members of a community. ### Method GET ### Endpoint /communities/{community_id}/members ### Parameters #### Path Parameters - **community_id** (string) - Required - The ID of the community. #### Query Parameters - **count** (integer) - Optional - The number of members to retrieve. Defaults to 20. - **cursor** (string) - Optional - Cursor for pagination. ### Response #### Success Response (200) - **Result** (object) - Contains a list of CommunityMember objects. - **members** (array) - List of CommunityMember objects. - **id** (string) - The ID of the community member. ### Response Example ```json { "members": [ { "id": "..." }, { "id": "..." } ] } ``` ``` -------------------------------- ### Create List Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Creates a new list with a specified name and description. The list can be set to private or public. ```python >>> list = await client.create_list( ... 'list name', ... 'list description', ... is_private=True ... ) >>> print(list) >> await client.get_user_followers(user_id='12345') >>> await client.get_user_followers(user_id='12345', count=50) ``` -------------------------------- ### Initialize Capsolver for Client Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Pass a configured Capsolver instance to the Client constructor to enable automatic captcha solving. ```python from twikit.twikit_async import Capsolver, Client solver = Capsolver( api_key='your_api_key', max_attempts=10 ) client = Client(captcha_solver=solver) ``` -------------------------------- ### Client Initialization Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Initializes the Twikit client for interacting with the Twitter API. Supports language selection, proxy configuration, and CAPTCHA solving. ```APIDOC ## Client Initialization ### Description Initializes the Twikit client for interacting with the Twitter API. Supports language selection, proxy configuration, and CAPTCHA solving. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```py from twikit.client import Client client = Client(language='en-US', proxy='http://0.0.0.0:0000') ``` ### Response None ``` -------------------------------- ### GET /trends/locations Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of locations where trends can be retrieved. ```APIDOC ## GET /trends/locations ### Description Retrieves locations where trends can be retrieved. ### Method GET ### Endpoint /trends/locations ### Response #### Success Response (200) - **locations** (list[Location]) - A list of Location objects representing available trend locations. ### Response Example ```json { "locations": [ { "name": "Worldwide", "woeid": 1 }, { "name": "United States", "woeid": 23424977 } ] } ``` ``` -------------------------------- ### Retrieve List Subscribers Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches subscribers of a list and demonstrates pagination. ```pycon >>> subscribers = list_.get_subscribers() >>> for subscriber in subscribers: ... print(subscriber) ... ... >>> more_subscribers = subscribers.next() # Retrieve more subscribers ``` -------------------------------- ### Load Cookies from File Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Load session cookies directly from a file to bypass the login process. ```pycon >>> client.load_cookies('cookies.json') ``` -------------------------------- ### GET /reverse_geocode Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Searches for places based on latitude and longitude. ```APIDOC ## GET /reverse_geocode ### Description Given a latitude and a longitude, searches for up to 20 places. ### Parameters #### Query Parameters - **lat** (float) - Required - The latitude to search around. - **long** (float) - Required - The longitude to search around. - **accuracy** (str|float) - Optional - A hint on the region in which to search. - **granularity** (str) - Optional - Minimal granularity of place types (neighborhood, city, admin, country). - **max_results** (int) - Optional - A hint as to the number of results to return. ### Response #### Success Response (200) - **places** (list[Place]) - A list of Place objects. ``` -------------------------------- ### POST /communities/{community_id}/join Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Join a community. ```APIDOC ## POST /communities/{community_id}/join ### Description Join a community. ### Method POST ### Endpoint /communities/{community_id}/join ### Parameters #### Path Parameters - **community_id** (string) - Required - The ID of the community to join. ### Response #### Success Response (200) - **Community** (object) - The joined community object. - **id** (string) - The ID of the community. ### Response Example ```json { "id": "..." } ``` ``` -------------------------------- ### GET /get_user_by_id Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches a user profile by their unique ID. ```APIDOC ## GET /get_user_by_id ### Description Fetches a user by ID. ### Parameters #### Query Parameters - **user_id** (str) - Required - The ID of the Twitter user. ### Response #### Success Response (200) - **user** (User) - An instance of the User class representing the Twitter user. ``` -------------------------------- ### Retrieve List Members Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches members of a list and demonstrates pagination. ```pycon >>> members = list_.get_members() >>> for member in members: ... print(member) ... ... >>> more_members = members.next() # Retrieve more members ``` -------------------------------- ### GET /tweet/favoriters Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieve a list of users who have favorited a specific tweet. ```APIDOC ## GET /tweet/favoriters ### Description Retrieve users who favorited a specific tweet. ### Method GET ### Parameters #### Query Parameters - **tweet_id** (str) - Required - The ID of the tweet. - **count** (int) - Optional - The maximum number of users to retrieve (default: 40). - **cursor** (str) - Optional - A string indicating the position of the cursor for pagination. ### Response #### Success Response (200) - **Result[User]** (list) - A list of users who favorited the tweet. ``` -------------------------------- ### Create a Tweet with Media Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Use this to create a tweet that includes uploaded media. Ensure media is uploaded first using `upload_media`. ```python >>> tweet_text = 'Example text' >>> media_ids = [ ... await client.upload_media('image1.png'), ... await client.upload_media('image2.png') ... ] >>> await client.create_tweet( ... tweet_text, ... media_ids=media_ids ... ) ``` -------------------------------- ### Search Users with Twikit Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Shows how to search for users and fetch subsequent pages of results. ```pycon >>> result = await client.search_user('query') >>> for user in result: ... print(user) ... ... ``` ```pycon >>> more_results = await result.next() # Retrieve more search results >>> for user in more_results: ... print(user) ... ... ``` -------------------------------- ### GET /tweet/retweeters Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieve a list of users who have retweeted a specific tweet. ```APIDOC ## GET /tweet/retweeters ### Description Retrieve users who retweeted the tweet. ### Method GET ### Parameters #### Query Parameters - **count** (int) - Optional - The maximum number of users to retrieve (default: 40). - **cursor** (str) - Optional - A string indicating the position of the cursor for pagination. ### Response #### Success Response (200) - **Result[User]** (list) - A list of users who retweeted the tweet. ``` -------------------------------- ### GET /get_list_tweets Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves tweets contained within a specific list. ```APIDOC ## GET /get_list_tweets ### Description Retrieves tweets from a list. ### Parameters #### Query Parameters - **list_id** (str) - Required - The ID of the list to retrieve tweets from. - **count** (int) - Optional - The number of tweets to retrieve (default 20). - **cursor** (str) - Optional - The cursor for pagination. ### Response - **Result[Tweet]** (object) - A Result object containing the retrieved tweets. ``` -------------------------------- ### GET /users/latest_friends Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves the latest users that a given user is following. ```APIDOC ## GET /users/latest_friends ### Description Retrieves the latest friends (following users). ### Method GET ### Endpoint /users/latest_friends ### Parameters #### Query Parameters - **user_id** (string) - Optional - The ID of the user for whom to retrieve friends. - **screen_name** (string) - Optional - The screen name of the user for whom to retrieve friends. - **count** (integer) - Optional - The number of friends to retrieve. Max count is 200. Defaults to 200. - **cursor** (string) - Optional - Used for pagination. ### Response #### Success Response (200) - **friends** (Result[User]) - A Result object containing a list of User objects representing the latest friends. ### Response Example ```json { "friends": { "users": [ { "id": "33333", "screen_name": "following_user1" }, { "id": "44444", "screen_name": "following_user2" } ], "next_cursor": "next_cursor_string" } } ``` ``` -------------------------------- ### GET /users/:user_id/followers Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of followers for a given user. ```APIDOC ## GET /users/:user_id/followers ### Description Retrieves a list of followers for a given user. ### Method GET ### Endpoint /users/{user_id}/followers ### Parameters #### Path Parameters - **user_id** (string) - Required - The ID of the user for whom to retrieve followers. #### Query Parameters - **count** (integer) - Optional - The number of followers to retrieve. Defaults to 20. - **cursor** (string) - Optional - Used for pagination to retrieve the next set of followers. ### Response #### Success Response (200) - **followers** (Result[User]) - A Result object containing a list of User objects representing the followers. ### Response Example ```json { "followers": { "users": [ { "id": "12345", "screen_name": "user1" }, { "id": "67890", "screen_name": "user2" } ], "next_cursor": "next_cursor_string" } } ``` ``` -------------------------------- ### create_media_metadata Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Adds alt text and sensitive content warnings to uploaded media. ```APIDOC ## create_media_metadata ### Description Updates metadata for a specific media ID. ### Parameters #### Request Body - **media_id** (str) - Required - The media ID. - **alt_text** (str) - Optional - Alternative text for accessibility. - **sensitive_warning** (list) - Optional - List of warnings: 'adult_content', 'graphic_violence', 'other'. ### Response - **response** (httpx.Response) - The response object from the Twitter API. ``` -------------------------------- ### Get Community Note Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches a community note by its unique ID. ```APIDOC ## GET /d60/twikit/community_note ### Description Fetches a community note by its ID. ### Method GET ### Endpoint /d60/twikit/community_note ### Parameters #### Query Parameters - **note_id** (str) - Required - The ID of the community note. ### Response #### Success Response (200) - **CommunityNote** (object) - A CommunityNote object representing the fetched note. #### Response Example { "id": "...", "text": "..." } ``` -------------------------------- ### Bookmarks Source: https://github.com/d60/twikit/blob/main/ratelimits.md Endpoints for managing user bookmarks. ```APIDOC ## POST /CreateBookmark ### Description Adds a tweet to the user's bookmarks. ### Method POST ### Endpoint /CreateBookmark ### Parameters #### Request Body - **tweet_id** (string) - Required - The ID of the tweet to bookmark. ### Request Example ```json { "tweet_id": "1234567890" } ``` ## GET /Bookmarks ### Description Retrieves all bookmarked tweets for the user. ### Method GET ### Endpoint /Bookmarks ### Response #### Success Response (200) - **bookmarks** (array) - A list of bookmarked tweets. #### Response Example ```json { "bookmarks": [ { "id": "tweet1", "text": "A bookmarked tweet." } ] } ``` ## POST /DeleteBookmark ### Description Removes a tweet from the user's bookmarks. ### Method POST ### Endpoint /DeleteBookmark ### Parameters #### Request Body - **bookmark_id** (string) - Required - The ID of the bookmark to delete. ### Request Example ```json { "bookmark_id": "bookmark456" } ``` ## POST /BookmarksAllDelete ### Description Deletes all bookmarks for the user. ### Method POST ### Endpoint /BookmarksAllDelete ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "All bookmarks deleted successfully." } ``` ``` -------------------------------- ### Get Favoriters Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches a list of users who have favorited a specific tweet. ```APIDOC ## GET /d60/twikit/favoriters ### Description Retrieves users who favorited a specific tweet. ### Method GET ### Endpoint /d60/twikit/favoriters ### Parameters #### Query Parameters - **tweet_id** (str) - Required - The ID of the tweet. - **count** (int) - Optional - The maximum number of users to retrieve (default: 40). - **cursor** (str) - Optional - A cursor for pagination. ### Response #### Success Response (200) - **Result[User]** (object) - A Result object containing a list of User objects who favorited the tweet. #### Response Example { "data": [ { "id": "...", "name": "...", "username": "..." } ], "next_cursor": "..." } ``` -------------------------------- ### Set Cookies from Dictionary Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Manually set session cookies from a dictionary, typically loaded from a file. ```pycon >>> with open('cookies.json', 'r', encoding='utf-8') as f: ... client.set_cookies(json.load(f)) ``` -------------------------------- ### Get Retweeters Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches a list of users who have retweeted a specific tweet. ```APIDOC ## GET /d60/twikit/retweeters ### Description Retrieves users who retweeted a specific tweet. ### Method GET ### Endpoint /d60/twikit/retweeters ### Parameters #### Query Parameters - **tweet_id** (str) - Required - The ID of the tweet. - **count** (int) - Optional - The maximum number of users to retrieve (default: 40). - **cursor** (str) - Optional - A cursor for pagination. ### Response #### Success Response (200) - **Result[User]** (object) - A Result object containing a list of User objects who retweeted the tweet. #### Response Example { "data": [ { "id": "...", "name": "...", "username": "..." } ], "next_cursor": "..." } ``` -------------------------------- ### Create Tweet with Media Source: https://github.com/d60/twikit/blob/main/README.md Upload media files to obtain IDs and attach them to a new tweet. ```python # Upload media files and obtain media_ids media_ids = [ await client.upload_media('media1.jpg'), await client.upload_media('media2.jpg') ] # Create a tweet with the provided text and attached media await client.create_tweet( text='Example Tweet', media_ids=media_ids ) ``` -------------------------------- ### Get Scheduled Tweets Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of all currently scheduled tweets. ```APIDOC ## GET /d60/twikit/scheduled_tweets ### Description Retrieves a list of all scheduled tweets. ### Method GET ### Endpoint /d60/twikit/scheduled_tweets ### Response #### Success Response (200) - **list[ScheduledTweet]** (array) - A list of ScheduledTweet objects. #### Response Example [ { "id": "...", "text": "...", "scheduled_at": "..." } ] ``` -------------------------------- ### Get Group Information Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Fetches information about a specific group using its ID. ```APIDOC ## GET /api/groups/{group_id} ### Description Fetches a guild by ID. ### Method GET ### Endpoint /api/groups/{group_id} ### Parameters #### Path Parameters - **group_id** (str) - Required - The ID of the group to retrieve information for. ### Response #### Success Response (200) - **Group** (object) - An object representing the retrieved group. #### Response Example ```json { "id": "...", "name": "..." } ``` ``` -------------------------------- ### Capsolver Configuration Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Configures the Capsolver instance to handle automated captcha solving during client initialization. ```APIDOC ## Capsolver Initialization ### Description Initializes the Capsolver instance to be used by the Client for automatic captcha solving. ### Parameters - **api_key** (str) - Required - Capsolver API key. - **max_attempts** (int) - Optional - The maximum number of attempts to solve the captcha (default: 3). - **get_result_interval** (float) - Optional - Interval in seconds between result checks (default: 1.0). - **use_blob_data** (bool) - Optional - Whether to use blob data (default: False). ### Request Example ```python from twikit.twikit_async import Capsolver, Client solver = Capsolver( api_key='your_api_key', max_attempts=10 ) client = Client(captcha_solver=solver) ``` ``` -------------------------------- ### Manage Session Cookies Source: https://context7.com/d60/twikit/llms.txt Persist login state by saving and loading cookies to avoid repeated authentication. ```python async def cookie_management_example(): # Login and save cookies await client.login( auth_info_1='username', auth_info_2='email@example.com', password='password', cookies_file='cookies.json' # Auto-saves after login ) # Or manually save cookies client.save_cookies('cookies.json') # Load cookies in a new session new_client = Client('en-US') new_client.load_cookies('cookies.json') # Get cookies as dict cookies = client.get_cookies() print(cookies) # Set cookies from dict client.set_cookies(cookies) ``` -------------------------------- ### GET /users/:user_id/subscriptions Source: https://github.com/d60/twikit/blob/main/docs/twikit.md Retrieves a list of users to which the specified user is subscribed. ```APIDOC ## GET /users/:user_id/subscriptions ### Description Retrieves a list of users to which the specified user is subscribed. ### Method GET ### Endpoint /users/{user_id}/subscriptions ### Parameters #### Path Parameters - **user_id** (string) - Required - The ID of the user for whom to retrieve subscriptions. #### Query Parameters - **count** (integer) - Optional - The number of subscriptions to retrieve. Defaults to 20. - **cursor** (string) - Optional - Used for pagination. ### Response #### Success Response (200) - **subscriptions** (Result[User]) - A Result object containing a list of User objects representing the subscribed users. ### Response Example ```json { "subscriptions": { "users": [ { "id": "12121", "screen_name": "subscribed_user1" }, { "id": "13131", "screen_name": "subscribed_user2" } ], "next_cursor": "next_cursor_string" } } ``` ```