Overview
TheClient class provides authenticated access to the Twitter API. All methods are asynchronous and must be executed using await.
Initialization
The language code to use in API requests (e.g., ‘en-US’, ‘ja-JP’).
The proxy server URL to use for requests (e.g., ‘http://0.0.0.0:8080’).
A Capsolver instance for automatic CAPTCHA solving. See the Capsolver documentation.
Custom user agent string. If not provided, a default user agent will be used.
Authentication
login
Logs into a Twitter account using the specified credentials.The first piece of authentication information: username, email address, or phone number.
The second piece of authentication information (optional but recommended). Can be username, email, or phone number.
The account password.
The TOTP secret key for two-factor authentication (2FA).
File path for storing/loading cookies. If the file exists, cookies are loaded from it, potentially bypassing login.
If True, executes obfuscated ui_metrics function to reduce account suspension risk.
Response data from the login flow.
logout
Logs out of the currently logged-in account.HTTP response from the logout request.
unlock
Unlocks the account using the provided CAPTCHA solver.Requires a
captcha_solver to be configured during client initialization.Cookie Management
get_cookies
Retrieves the current session cookies.Dictionary containing session cookies.
save_cookies
Saves cookies to a file in JSON format.File path where cookies will be saved.
load_cookies
Loads cookies from a file.Path to the file containing saved cookies.
set_cookies
Sets cookies from a dictionary.Dictionary of cookies to set.
If True, clears existing cookies before setting new ones.
User Operations
user_id
Retrieves the user ID of the authenticated account.The user ID of the authenticated account.
user
Retrieves detailed information about the authenticated user.User object with detailed information about the authenticated user.
get_user_by_screen_name
Fetches a user by their screen name (username).The screen name (username) of the Twitter user.
User object representing the Twitter user.
get_user_by_id
Fetches a user by their user ID.The ID of the Twitter user.
User object representing the Twitter user.
follow_user
Follows a user.The ID of the user to follow.
The followed user.
unfollow_user
Unfollows a user.The ID of the user to unfollow.
The unfollowed user.
block_user
Blocks a user.The ID of the user to block.
The blocked user.
unblock_user
Unblocks a user.The ID of the user to unblock.
The unblocked user.
mute_user
Mutes a user.The ID of the user to mute.
The muted user.
unmute_user
Unmutes a user.The ID of the user to unmute.
The unmuted user.
get_user_tweets
Fetches tweets from a specific user’s timeline.The ID of the Twitter user whose tweets to retrieve.
The type of tweets to retrieve.
The number of tweets to retrieve.
Cursor for pagination.
A Result object containing a list of Tweet objects with pagination support.
get_user_highlights_tweets
Retrieves highlighted tweets from a user’s timeline.The user ID.
The number of tweets to retrieve.
Cursor for pagination.
Result object containing highlighted tweets.
get_user_followers
Retrieves a list of followers for a given user.The ID of the user for whom to retrieve followers.
The number of followers to retrieve.
Cursor for pagination.
Result object containing User objects representing followers.
get_user_verified_followers
Retrieves a list of verified followers for a given user.The ID of the user.
The number of verified followers to retrieve.
Cursor for pagination.
Result object containing verified followers.
get_user_followers_you_know
Retrieves a list of common followers (followers you both follow).The ID of the user.
The number of common followers to retrieve.
Cursor for pagination.
Result object containing common followers.
get_user_following
Retrieves a list of users whom the given user is following.The ID of the user.
The number of following users to retrieve.
Cursor for pagination.
Result object containing User objects representing followed users.
get_user_subscriptions
Retrieves a list of users to which the specified user is subscribed.The ID of the user.
The number of subscriptions to retrieve.
Cursor for pagination.
Result object containing subscribed users.
get_latest_followers
Retrieves the latest followers (max count: 200).The ID of the user.
The screen name of the user.
The maximum number of followers to retrieve (max 200).
Cursor for pagination.
Result object containing latest followers.
get_latest_friends
Retrieves the latest friends/following users (max count: 200).The ID of the user.
The screen name of the user.
The maximum number of friends to retrieve (max 200).
Cursor for pagination.
Result object containing latest friends.
get_followers_ids
Fetches the IDs of the followers of a specified user.The ID of the user.
The screen name of the user.
The maximum number of IDs to retrieve.
Cursor for pagination.
Result object containing follower IDs.
get_friends_ids
Fetches the IDs of the friends (following users) of a specified user.The ID of the user.
The screen name of the user.
The maximum number of IDs to retrieve.
Cursor for pagination.
Result object containing friend IDs.
Tweet Operations
create_tweet
Creates a new tweet with text, media, and/or poll.The text content of the tweet.
A list of media IDs to attach. Media IDs are obtained via
upload_media().The URI of a Twitter poll card. Poll URIs are obtained via
create_poll().The ID of the tweet to which this tweet is a reply.
Limits who can reply:
'followers': Only followers can reply'verified': Only verified accounts can reply'mentioned': Only mentioned accounts can reply
URL of the tweet to quote.
ID of the community to post in.
If True, shares community tweet with followers.
If True, allows tweets longer than 280 characters (Twitter Premium only).
Options for text formatting (Twitter Premium only).
ID of the tweet to edit (Twitter Premium only).
The created Tweet object.
delete_tweet
Deletes a tweet.ID of the tweet to delete.
HTTP response from the API.
get_tweet_by_id
Fetches a tweet by its ID.The ID of the tweet.
Cursor for pagination.
Tweet object with replies, reply_to, and related_tweets populated.
get_tweets_by_ids
Retrieves multiple tweets by their IDs.A list of tweet IDs to retrieve.
List of Tweet objects.
search_tweet
Searches for tweets based on a query.The search query.
The type of tweets to retrieve:
'Top': Most relevant tweets'Latest': Most recent tweets'Media': Tweets with media
Number of tweets to retrieve (1-20).
Token to retrieve more tweets.
Result object containing search results with pagination.
get_scheduled_tweets
Retrieves scheduled tweets.List of ScheduledTweet objects.
create_scheduled_tweet
Schedules a tweet for posting at a specified time.Unix timestamp when the tweet should be posted.
The text content of the tweet.
List of media IDs to attach.
The ID of the scheduled tweet.
delete_scheduled_tweet
Deletes a scheduled tweet.The ID of the scheduled tweet to delete.
HTTP response from the API.
get_similar_tweets
Retrieves tweets similar to a specified tweet (Twitter Premium only).The ID of the tweet.
List of similar tweets.
favorite_tweet
Likes a tweet.The ID of the tweet to like.
HTTP response from the API.
unfavorite_tweet
Unlikes a tweet.The ID of the tweet to unlike.
HTTP response from the API.
retweet
Retweets a tweet.The ID of the tweet to retweet.
HTTP response from the API.
delete_retweet
Removes a retweet.The ID of the retweeted tweet.
HTTP response from the API.
get_retweeters
Retrieves users who retweeted a specific tweet.The ID of the tweet.
The maximum number of users to retrieve.
Cursor for pagination.
Result object containing users who retweeted.
get_favoriters
Retrieves users who liked a specific tweet.The ID of the tweet.
The maximum number of users to retrieve.
Cursor for pagination.
Result object containing users who liked the tweet.
get_community_note
Fetches a community note by ID.The ID of the community note.
CommunityNote object.
Timeline Operations
get_timeline
Retrieves the “For You” timeline.The number of tweets to retrieve.
List of tweet IDs that have been seen.
Cursor for pagination.
Result object containing timeline tweets.
get_latest_timeline
Retrieves the “Following” timeline.The number of tweets to retrieve.
List of tweet IDs that have been seen.
Cursor for pagination.
Result object containing timeline tweets.
Media Operations
upload_media
Uploads media to Twitter.File path or bytes of the media content.
Whether to wait for media processing to complete.
Interval in seconds to check upload status.
MIME type of the media. Auto-detected if not specified.
Media category (e.g., ‘tweet_gif’, ‘dm_gif’).
If True, allows videos longer than 2:20 (Twitter Premium only).
The media ID of the uploaded media.
check_media_status
Checks the processing status of uploaded media.The media ID of the uploaded media.
Whether this is a long video upload.
Dictionary containing media processing status information.
create_media_metadata
Adds metadata (alt text and content warnings) to uploaded media.The media ID for which to create metadata.
Alternative text description for the media.
List of sensitive content warnings.
HTTP response from the API.
Poll Operations
create_poll
Creates a poll and returns its card URI.List of poll choices (maximum 4).
Poll duration in minutes.
The URI of the created poll card.
vote
Votes on a poll.The label of the selected choice.
The URI of the poll card.
The ID of the tweet containing the poll.
The name of the poll card.
Updated Poll object after voting.
Bookmark Operations
bookmark_tweet
Adds a tweet to bookmarks.The ID of the tweet to bookmark.
The ID of the folder to add the bookmark to.
HTTP response from the API.
delete_bookmark
Removes a tweet from bookmarks.The ID of the tweet to remove from bookmarks.
HTTP response from the API.
get_bookmarks
Retrieves bookmarked tweets.The number of bookmarks to retrieve.
Cursor for pagination.
Folder ID to retrieve bookmarks from.
Result object containing bookmarked tweets.
delete_all_bookmarks
Deletes all bookmarks.HTTP response from the API.
get_bookmark_folders
Retrieves bookmark folders.Cursor for pagination.
Result object containing bookmark folders.
create_bookmark_folder
Creates a new bookmark folder.Name of the folder.
The created bookmark folder.
edit_bookmark_folder
Edits a bookmark folder’s name.ID of the folder to edit.
New name for the folder.
The updated bookmark folder.
delete_bookmark_folder
Deletes a bookmark folder.ID of the folder to delete.
HTTP response from the API.
Direct Message Operations
send_dm
Sends a direct message to a user.The ID of the user to send the message to.
The text content of the message.
Media ID to include in the message. Obtained via
upload_media().Message ID to reply to.
Message object containing information about the sent message.
delete_dm
Deletes a direct message.The ID of the message to delete.
HTTP response from the API.
get_dm_history
Retrieves DM conversation history with a user.The ID of the user.
If specified, retrieves messages older than this message ID.
Result object containing messages.
add_reaction_to_message
Adds an emoji reaction to a message.The ID of the message.
The ID of the conversation. Format:
partner_id-your_id or group ID.The emoji to add as a reaction.
HTTP response from the API.
remove_reaction_from_message
Removes an emoji reaction from a message.The ID of the message.
The ID of the conversation.
The emoji reaction to remove.
HTTP response from the API.
Group Message Operations
send_dm_to_group
Sends a message to a group.The ID of the group.
The text content of the message.
Media ID to include.
Message ID to reply to.
GroupMessage object containing information about the sent message.
get_group_dm_history
Retrieves DM history from a group.The ID of the group.
If specified, retrieves messages older than this message ID.
Result object containing group messages.
get_group
Retrieves information about a group.The ID of the group.
Group object containing group information.
add_members_to_group
Adds members to a group.ID of the group.
List of user IDs to add.
HTTP response from the API.
change_group_name
Changes a group’s name.ID of the group.
New name for the group.
HTTP response from the API.
List Operations
create_list
Creates a new list.The name of the list.
The description of the list.
Whether the list is private (True) or public (False).
The created List object.
get_list
Retrieves a list by ID.The ID of the list.
List object.
get_lists
Retrieves user’s lists.The number of lists to retrieve.
Cursor for pagination.
Result object containing lists.
edit_list
Edits list information.The ID of the list to edit.
New name for the list.
New description for the list.
Whether the list should be private.
The updated List object.
add_list_member
Adds a user to a list.The ID of the list.
The ID of the user to add.
The updated List object.
remove_list_member
Removes a user from a list.The ID of the list.
The ID of the user to remove.
The updated List object.
get_list_tweets
Retrieves tweets from a list.The ID of the list.
The number of tweets to retrieve.
Cursor for pagination.
Result object containing tweets from the list.
get_list_members
Retrieves members of a list.The ID of the list.
Number of members to retrieve.
Cursor for pagination.
Result object containing list members.
get_list_subscribers
Retrieves subscribers of a list.The ID of the list.
Number of subscribers to retrieve.
Cursor for pagination.
Result object containing list subscribers.
search_list
Searches for lists based on a query.The search query.
The number of lists to retrieve.
Cursor for pagination.
Result object containing search results.
edit_list_banner
Edits the banner image of a list.The ID of the list.
The ID of the media to use as banner.
HTTP response from the API.
delete_list_banner
Deletes a list’s banner.The ID of the list.
HTTP response from the API.
Community Operations
search_community
Searches for communities.The search query.
Cursor for pagination.
Result object containing communities.
get_community
Retrieves a community by ID.The ID of the community.
Community object.
join_community
Joins a community.The ID of the community to join.
The joined community.
leave_community
Leaves a community.The ID of the community to leave.
The left community.
request_to_join_community
Requests to join a private community.The ID of the community.
Answer to the join request question.
The requested community.
get_community_tweets
Retrieves tweets from a community.The ID of the community.
The type of tweets to retrieve.
The number of tweets to retrieve.
Cursor for pagination.
Result object containing community tweets.
get_communities_timeline
Retrieves tweets from communities timeline.The number of tweets to retrieve.
Cursor for pagination.
Result object containing tweets from communities.
get_community_members
Retrieves members of a community.The ID of the community.
The number of members to retrieve.
Cursor for pagination.
Result object containing community members.
get_community_moderators
Retrieves moderators of a community.The ID of the community.
The number of moderators to retrieve.
Cursor for pagination.
Result object containing community moderators.
search_community_tweet
Searches for tweets in a community.The ID of the community.
The search query.
The number of tweets to retrieve.
Cursor for pagination.
Result object containing search results.
Notification Operations
get_notifications
Retrieves notifications.Type of notifications to retrieve:
'All': All notifications'Verified': Notifications from verified users'Mentions': Mention notifications
Number of notifications to retrieve.
Cursor for pagination.
Result object containing notifications.
Trend Operations
get_trends
Retrieves trending topics.The category of trends to retrieve.
The number of trends to retrieve.
If True, continuously retries if no trends are fetched.
Additional parameters for the API request.
List of Trend objects.
get_available_locations
Retrieves locations where trends can be retrieved.List of available locations.
get_place_trends
Retrieves the top 50 trending topics for a specific location.Where On Earth ID. Can be obtained from
get_available_locations().Dictionary containing place trends information.
Geolocation Operations
reverse_geocode
Searches for places near a latitude and longitude.The latitude to search around.
The longitude to search around.
A hint on the region size.
Minimal granularity: ‘neighborhood’, ‘city’, ‘admin’, or ‘country’.
Maximum number of results.
List of Place objects.
search_geo
Searches for places that can be attached to tweets.The latitude to search around.
The longitude to search around.
Free-form text to match (e.g., location name).
IP address for geolocation.
Minimal granularity: ‘neighborhood’, ‘city’, ‘admin’, or ‘country’.
Maximum number of results.
List of Place objects.
get_place
Retrieves a place by ID.The ID of the place.
Place object.
Streaming API
get_streaming_session
Returns a session for interacting with the streaming API.Set of topics to stream. Use
Topic class to generate topic strings.Whether to automatically reconnect when disconnected.
A streaming session instance.
Topics can be added or removed using
session.update_subscriptions(subscribe_topics, unsubscribe_topics).Search Operations
search_user
Searches for users.The search query.
The number of users to retrieve.
Cursor for pagination.
Result object containing search results.
Delegation
set_delegate_account
Sets the account to act as (for delegated accounts).The user ID of the account to act as. Set to None to clear.
This allows authenticated users with delegation permissions to perform actions on behalf of other accounts.
