UsersClient provides methods for interacting with user-related endpoints of the X API. Access it via client.users.
get_me
Retrieves details of the authenticated user.Parameters
A comma separated list of User fields to display. Available fields include:
created_atdescriptionentitiesidlocationnamepinned_tweet_idprofile_image_urlprotectedpublic_metricsurlusernameverifiedverified_type
A comma separated list of fields to expand. Available expansions include:
pinned_tweet_id
A comma separated list of Tweet fields to display when expanding pinned tweets.
Response
The authenticated User object containing user details.
Any errors encountered during the request.
Expanded data such as pinned tweets.
get_by_id
Retrieves details of a specific User by their ID.Parameters
The ID of the User to lookup.
A comma separated list of User fields to display.
A comma separated list of fields to expand.
A comma separated list of Tweet fields to display.
Response
The User object matching the specified ID.
Any errors encountered during the request.
Expanded data if requested.
get_by_username
Retrieves details of a specific User by their username.Parameters
The username of the User to lookup (without the @ symbol).
A comma separated list of User fields to display.
A comma separated list of fields to expand.
A comma separated list of Tweet fields to display.
Response
The User object matching the specified username.
Any errors encountered during the request.
Expanded data if requested.
search
Retrieves a list of Users matching a search query. This method automatically paginates through all results.Parameters
The query string by which to search for users.
The maximum number of results per page (1-100). Defaults to 10.
This parameter is used to get the next ‘page’ of results. The value is pulled directly from the response.
A comma separated list of User fields to display.
A comma separated list of fields to expand.
A comma separated list of Tweet fields to display.
Response
Returns an iterator that yieldsSearchResponse objects for each page.
A list of User objects matching the search query.
Metadata about the response including pagination tokens.
Any errors encountered during the request.
follow_user
Causes the authenticated user to follow a specific user by their ID.Parameters
The ID of the authenticated source User that is requesting to follow the target User.
Request body containing the target user ID.
Response
Response data indicating the follow status.
Any errors encountered during the request.
get_followers
Retrieves a list of Users who follow a specific User by their ID. This method automatically paginates through all results.Parameters
The ID of the User to lookup followers for.
The maximum number of results per page (1-1000). Defaults to 100.
This parameter is used to get a specified ‘page’ of results.
A comma separated list of User fields to display.
A comma separated list of fields to expand.
A comma separated list of Tweet fields to display.
Response
Returns an iterator that yieldsGetFollowersResponse objects for each page.
A list of User objects representing followers.
Metadata about the response including pagination tokens.
Any errors encountered during the request.
Expanded data if requested.
get_following
Retrieves a list of Users followed by a specific User by their ID. This method automatically paginates through all results.Parameters
The ID of the User to lookup following for.
The maximum number of results per page (1-1000). Defaults to 100.
This parameter is used to get a specified ‘page’ of results.
A comma separated list of User fields to display.
A comma separated list of fields to expand.
A comma separated list of Tweet fields to display.
Response
Returns an iterator that yieldsGetFollowingResponse objects for each page.
A list of User objects being followed.
Metadata about the response including pagination tokens.
Any errors encountered during the request.
Expanded data if requested.
Authentication
All methods in the UsersClient require authentication. The authentication method used depends on the endpoint:- OAuth 2.0 User Context: Required for
get_me,follow_user, andsearch - OAuth 1.0a User Context: Supported as an alternative for most endpoints
- App-only (Bearer Token): Supported for read-only endpoints like
get_by_id,get_by_username,get_followers, andget_following