Use the TwexAPI Ruby SDK to search tweets, scrape Twitter followers, and read X profiles, timelines, replies, and threads. Send DMs, search communities, fetch lists, articles, hashtags, cashtags, and global trending tweets with typed request objects. Like, retweet, follow, and post through documented REST routes. It is a Twitter API alternative for apps and scripts.
REST API | TypeScript SDK | Dashboard
Speakeasy generates this SDK.
| Task | REST Route | Usage |
|---|---|---|
| Search tweets without the X API | POST /twitter/advanced_search/page |
Use keyword queries and paginate with a cursor. |
| Search hashtags or cashtags | POST /twitter/hashtags, POST /twitter/cashtags |
Filter by tag and sort order. |
| Read an X profile | GET /twitter/{screen_name}/about |
Look up a user by screen name. |
| Read a profile timeline | GET /twitter/{screen_name}/timeline/page |
Paginate bounded results. |
| Scrape Twitter followers | POST /v3/twitter/users/followers |
Use the v3 follower list. |
| Scrape following accounts | POST /v3/twitter/users/following |
Use the v3 following list. |
| Read tweet replies | POST /twitter/tweets/{tweet_id}/replies/page |
Paginate replies by tweet id. |
| Read a tweet thread | POST /twitter/tweets/thread_by_id |
Fetch the thread from a root tweet. |
| Send or read DMs | /v3/twitter/send-dm, /v3/twitter/dm-history |
Use v3 XChat endpoints. |
| Search communities | POST /twitter/community/search |
Find communities, then load tweets or members. |
| Get global trending tweets | GET /twitter/global-trending/tweets |
Filter by country, topic, and content. |
| Post or reply | POST /twitter/tweets/create |
Confirm the account cookie and payload. |
- Package:
x_api_scraper - Source: twexapi-dev/x-api-scraper-ruby
- Docs: docs.twexapi.io
- License: MIT
- Dashboard: twexapi.io/dashboard
X API Scraper: Speakeasy-ready OpenAPI document for the x-api-scraper TypeScript SDK.
The SDK wraps TwexAPI's X/Twitter API surface with bearer-token authentication. Cookie/proxy based endpoints are excluded except tweet actions, follow/unfollow, and v3 DM operations. Paid engagement services, profile mutation, legacy-only operations, and non-v3 follower/following endpoints remain excluded.
Not affiliated with X Corp.
Requires Ruby 3.2.0 or higher.
Add the gem to your Gemfile:
gem "x_api_scraper", "~> 0.1.0"Or install from GitHub until the gem is published:
gem "x_api_scraper", git: "https://github.com/twexapi-dev/x-api-scraper-ruby.git"require "x_api_scraper"
Models = ::XapiScraper::Models
client = ::XapiScraper::Client.new(
bearer_auth: ENV["X_API_SCRAPER_KEY"]
)
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: ["from:elonmusk"],
sort_by: "Latest",
next_cursor: ""
)
res = client.search.advanced(request: req)
puts(res.advanced_search_cursor_response)
about = client.users.get_about(
request: Models::Operations::UsersGetAboutRequest.new(screen_name: "elonmusk")
)
followers = client.users.followers.list(
request: Models::Components::FollowersFollowingV3Query.new(username: "elonmusk")
)Get an API key from the TwexAPI dashboard. Pass it as bearer_auth, or set X_API_SCRAPER_KEY.
Write actions (tweet, follow, like, DM send) also need a Twitter cookie or auth_token on the request. Pass them on the operation input.
Keep API keys out of source code, URLs, and logs.
This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
bearer_auth |
http | HTTP Bearer |
To authenticate with the API the bearer_auth parameter must be set when initializing the SDK client instance. For example:
require "x_api_scraper"
Models = ::XapiScraper::Models
s = ::XapiScraper::Client.new(
bearer_auth: "<YOUR_BEARER_TOKEN_HERE>"
)
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: [
"<value 1>",
"<value 2>",
"<value 3>"
],
sort_by: "<value>",
next_cursor: ""
)
res = s.search.advanced(request: req)
unless res.advanced_search_cursor_response.nil?
# handle response
endAvailable methods
- balance - Get Balance
- sentiment - Sentiment Analysis
- members - Get Community Members
- members_page - Get Community Members by Page
- tweets - Get Community Tweets
- tweets_page - Get Community Tweets by Page
- search - Search Community
- get - Get Community
- search_tweets - Search Community Tweets
- status - Check DM Permissions
- send - Send DM
- history - Get DM History
- media - Get DM Media
- conversations - Get Conversations
- tweets - Get List Tweets
- tweets_page - Get List Tweets by Page
- subscribers - Get List Subscribers
- members - Get List Members
- members_page - Get List Members by Page
- search - Search List
- tweets_and_replies - Get All Tweets and Replies by User
- user_page - Get User Timeline by Page
- user - Get User Timeline and Fill Count
- tweets_and_replies_page - Get All Tweets and Replies by User by Page
- countries - List Global Trend Countries
- topics - List Global Trend Topics
- contents - List Global Trend Content Tags
- tweets - Get Global Trending Tweets
- by_country - Get Trending Topics
- detail - Get Tweet Detail
- thread - Get Tweet Thread by ID
- lookup - Batch Get Tweets by ID
- similar - Get Similar Tweets
- like - Like a Tweet
- unlike - Unlike a Tweet
- retweet - Retweet a Tweet
- unretweet - Delete Retweet
- create_thread - Create a Tweet Thread
- create - Create a Tweet or Reply
- quote - Create a Quote Tweet
- create_without_cookie - Post Tweet (Auto Cookie)
- bookmark - Bookmark a Tweet
- unbookmark - Delete Bookmark
- delete_batch - Delete One or More Tweets
- retweeters - Get Retweeters
- retweeters_page - Get Retweeters by Page
- quotes - Get Quote Tweets
- quotes_page - Get Quote Tweets by Page
- page - Get Replies by Page
- get_by_usernames - Get Multiple Users by Usernames
- get_by_ids - Users Details by ID
- verify_account - Verify Account Status
- get_statuses - Batch Get User account status
- search - Search User
- follow - Follow User
- unfollow - Unfollow User
- get_account_based - Get Twitter Account Based in
- get_about - Get Twitter User About by Screen Name
- list - Get Following (v3)
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a RetryConfig object to the call:
require "x_api_scraper"
Models = ::XapiScraper::Models
s = ::XapiScraper::Client.new(
bearer_auth: "<YOUR_BEARER_TOKEN_HERE>"
)
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: [
"<value 1>",
"<value 2>",
"<value 3>"
],
sort_by: "<value>",
next_cursor: ""
)
res = s.search.advanced(request: req)
unless res.advanced_search_cursor_response.nil?
# handle response
endIf you'd like to override the default retry strategy for all operations that support retries, you can use the retry_config optional parameter when initializing the SDK:
require "x_api_scraper"
Models = ::XapiScraper::Models
s = ::XapiScraper::Client.new(
retry_config: Utils::RetryConfig.new(
backoff: Utils::BackoffStrategy.new(
exponent: 1.1,
initial_interval: 1,
max_elapsed_time: 100,
max_interval: 50
),
retry_connection_errors: false,
strategy: "backoff"
),
bearer_auth: "<YOUR_BEARER_TOKEN_HERE>"
)
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: [
"<value 1>",
"<value 2>",
"<value 3>"
],
sort_by: "<value>",
next_cursor: ""
)
res = s.search.advanced(request: req)
unless res.advanced_search_cursor_response.nil?
# handle response
endHandling errors in this SDK should largely match your expectations. All operations return a response object or raise an error.
By default an API error will raise a Errors::APIError, which has the following properties:
| Property | Type | Description |
|---|---|---|
message |
string | The error message |
status_code |
int | The HTTP status code |
raw_response |
Faraday::Response | The raw HTTP response |
body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the advanced method throws the following exceptions:
| Error Type | Status Code | Content Type |
|---|---|---|
| Models::Errors::HTTPValidationError | 422 | application/json |
| Errors::APIError | 4XX, 5XX | */* |
require "x_api_scraper"
Models = ::XapiScraper::Models
s = ::XapiScraper::Client.new(
bearer_auth: "<YOUR_BEARER_TOKEN_HERE>"
)
begin
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: [
"<value 1>",
"<value 2>",
"<value 3>"
],
sort_by: "<value>",
next_cursor: ""
)
res = s.search.advanced(request: req)
unless res.advanced_search_cursor_response.nil?
# handle response
end
rescue Models::Errors::HTTPValidationError => e
# handle e.container data
raise e
rescue Errors::APIError => e
# handle default exception
raise e
endYou can override the default server globally by passing a server name to the server (Symbol) optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
| Name | Server | Description |
|---|---|---|
production |
https://api.twexapi.io |
TwexAPI production API |
require "x_api_scraper"
Models = ::XapiScraper::Models
s = ::XapiScraper::Client.new(
server: "production",
bearer_auth: "<YOUR_BEARER_TOKEN_HERE>"
)
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: [
"<value 1>",
"<value 2>",
"<value 3>"
],
sort_by: "<value>",
next_cursor: ""
)
res = s.search.advanced(request: req)
unless res.advanced_search_cursor_response.nil?
# handle response
endThe default server can also be overridden globally by passing a URL to the server_url (String) optional parameter when initializing the SDK client instance. For example:
require "x_api_scraper"
Models = ::XapiScraper::Models
s = ::XapiScraper::Client.new(
server_url: "https://api.twexapi.io",
bearer_auth: "<YOUR_BEARER_TOKEN_HERE>"
)
req = Models::Components::AdvancedSearchCursorQuery.new(
search_terms: [
"<value 1>",
"<value 2>",
"<value 3>"
],
sort_by: "<value>",
next_cursor: ""
)
res = s.search.advanced(request: req)
unless res.advanced_search_cursor_response.nil?
# handle response
endThis SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
To regenerate from the OpenAPI document:
speakeasy runThe source spec lives in openapi.sdk.json. Keep it in sync with x-api-scraper-typescript.
GitHub Actions can regenerate the SDK and publish the gem. Add these repository secrets first:
SPEAKEASY_API_KEYRUBYGEMS_AUTH_TOKEN
TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.