Class: XTwitterScraper::Resources::X::Tweets

Inherits:
Object
  • Object
show all
Defined in:
lib/x_twitter_scraper/resources/x/tweets.rb,
lib/x_twitter_scraper/resources/x/tweets/like.rb,
lib/x_twitter_scraper/resources/x/tweets/retweet.rb,
sig/x_twitter_scraper/resources/x/tweets.rbs,
sig/x_twitter_scraper/resources/x/tweets/like.rbs,
sig/x_twitter_scraper/resources/x/tweets/retweet.rbs

Defined Under Namespace

Classes: Like, Retweet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Tweets

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Tweets.

Parameters:



549
550
551
552
553
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 549

def initialize(client:)
  @client = client
  @like = XTwitterScraper::Resources::X::Tweets::Like.new(client: client)
  @retweet = XTwitterScraper::Resources::X::Tweets::Retweet.new(client: client)
end

Instance Attribute Details

#likeXTwitterScraper::Resources::X::Tweets::Like (readonly)

X write actions (tweets, likes, follows, DMs)



9
10
11
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 9

def like
  @like
end

#retweetXTwitterScraper::Resources::X::Tweets::Retweet (readonly)

X write actions (tweets, likes, follows, DMs)



13
14
15
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 13

def retweet
  @retweet
end

Instance Method Details

#create(account:, attachment_url: nil, community_id: nil, is_note_tweet: nil, media: nil, reply_to_tweet_id: nil, text: nil, request_options: {}) ⇒ XTwitterScraper::Models::X::TweetCreateResponse

Some parameter documentations has been truncated, see Models::X::TweetCreateParams for more details.

Create tweet

Parameters:

  • account (String)

    X account (@username or account ID)

  • attachment_url (String)
  • community_id (String)
  • is_note_tweet (Boolean)
  • media (Array<String>)

    Array of public media URLs to attach. Supports up to 4 images or exactly 1 MP4 v

  • reply_to_tweet_id (String)
  • text (String)

    Tweet text (optional when media is provided)

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



41
42
43
44
45
46
47
48
49
50
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 41

def create(params)
  parsed, options = XTwitterScraper::X::TweetCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "x/tweets",
    body: parsed,
    model: XTwitterScraper::Models::X::TweetCreateResponse,
    options: options
  )
end

#delete(id, account:, request_options: {}) ⇒ XTwitterScraper::Models::X::TweetDeleteResponse

Delete tweet

Parameters:

  • id (String)

    Tweet ID to delete

  • account (String)

    X account identifier (@username or account ID)

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 108

def delete(id, params)
  parsed, options = XTwitterScraper::X::TweetDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["x/tweets/%1$s", id],
    body: parsed,
    model: XTwitterScraper::Models::X::TweetDeleteResponse,
    options: options
  )
end

#get_favoriters(id, cursor: nil, page_size: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Some parameter documentations has been truncated, see Models::X::TweetGetFavoritersParams for more details.

List users who liked a tweet

Parameters:

  • id (String)

    Tweet ID to get favoriters

  • cursor (String)

    Pagination cursor for favoriters

  • page_size (Integer)

    Maximum user profiles requested from this page (20-200, default 200). The respon

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 137

def get_favoriters(id, params = {})
  parsed, options = XTwitterScraper::X::TweetGetFavoritersParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/tweets/%1$s/favoriters", id],
    query: query.transform_keys(page_size: "pageSize"),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#get_quotes(id, any_words: nil, cashtags: nil, conversation_id: nil, cursor: nil, exact_phrase: nil, exclude_words: nil, from_user: nil, hashtags: nil, include_replies: nil, in_reply_to_tweet_id: nil, language: nil, media_type: nil, mentioning: nil, min_faves: nil, min_quotes: nil, min_replies: nil, min_retweets: nil, page_size: nil, quotes: nil, quotes_of_tweet_id: nil, replies: nil, retweets: nil, retweets_of_tweet_id: nil, since_date: nil, since_time: nil, to_user: nil, until_date: nil, until_time: nil, url: nil, verified_only: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Some parameter documentations has been truncated, see Models::X::TweetGetQuotesParams for more details.

List quote tweets of a tweet

Parameters:

  • id (String)

    Numeric tweet ID to get quotes, 15-20 digits

  • any_words (String)

    Words or quoted phrases where any one can match. Separate with spaces, commas, o

  • cashtags (String)

    Cashtags separated by spaces, commas, or lines.

  • conversation_id (String)

    Conversation ID filter.

  • cursor (String)

    Pagination cursor for quote tweets

  • exact_phrase (String)

    Exact phrase to match.

  • exclude_words (String)

    Words or quoted phrases to exclude. Separate with spaces, commas, or lines.

  • from_user (String)

    Filter by author username.

  • hashtags (String)

    Hashtags separated by spaces, commas, or lines.

  • include_replies (Boolean)

    Include reply quotes (default false)

  • in_reply_to_tweet_id (String)

    Only replies to this tweet ID.

  • language (String)

    Language code filter, e.g. en or tr.

  • media_type (Symbol, XTwitterScraper::Models::X::TweetGetQuotesParams::MediaType)

    Filter by media type.

  • mentioning (String)

    Filter tweets mentioning a username.

  • min_faves (Integer)

    Minimum likes threshold.

  • min_quotes (Integer)

    Minimum quote count threshold.

  • min_replies (Integer)

    Minimum replies threshold.

  • min_retweets (Integer)

    Minimum retweets threshold.

  • page_size (Integer)

    Maximum items requested from this page (1-100, default 20). The response can con

  • quotes (Symbol, XTwitterScraper::Models::X::TweetGetQuotesParams::Quotes)

    Quote mode.

  • quotes_of_tweet_id (String)

    Only quotes of this tweet ID.

  • replies (Symbol, XTwitterScraper::Models::X::TweetGetQuotesParams::Replies)

    Reply mode.

  • retweets (Symbol, XTwitterScraper::Models::X::TweetGetQuotesParams::Retweets)

    Retweet mode.

  • retweets_of_tweet_id (String)

    Only retweets of this tweet ID.

  • since_date (Date)

    Start date in YYYY-MM-DD format.

  • since_time (String)

    Unix timestamp - return quotes posted after this time

  • to_user (String)

    Filter replies sent to a username.

  • until_date (Date)

    End date in YYYY-MM-DD format.

  • until_time (String)

    Unix timestamp - return quotes posted before this time

  • url (String)

    URL substring or domain filter.

  • verified_only (Boolean)

    Only return tweets from verified authors.

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 223

def get_quotes(id, params = {})
  parsed, options = XTwitterScraper::X::TweetGetQuotesParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/tweets/%1$s/quotes", id],
    query: query.transform_keys(
      any_words: "anyWords",
      conversation_id: "conversationId",
      exact_phrase: "exactPhrase",
      exclude_words: "excludeWords",
      from_user: "fromUser",
      include_replies: "includeReplies",
      in_reply_to_tweet_id: "inReplyToTweetId",
      media_type: "mediaType",
      min_faves: "minFaves",
      min_quotes: "minQuotes",
      min_replies: "minReplies",
      min_retweets: "minRetweets",
      page_size: "pageSize",
      quotes_of_tweet_id: "quotesOfTweetId",
      retweets_of_tweet_id: "retweetsOfTweetId",
      since_date: "sinceDate",
      since_time: "sinceTime",
      to_user: "toUser",
      until_date: "untilDate",
      until_time: "untilTime",
      verified_only: "verifiedOnly"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#get_replies(id, any_words: nil, cashtags: nil, conversation_id: nil, cursor: nil, exact_phrase: nil, exclude_words: nil, from_user: nil, hashtags: nil, in_reply_to_tweet_id: nil, language: nil, media_type: nil, mentioning: nil, min_faves: nil, min_quotes: nil, min_replies: nil, min_retweets: nil, page_size: nil, quotes: nil, quotes_of_tweet_id: nil, replies: nil, retweets: nil, retweets_of_tweet_id: nil, since_date: nil, since_time: nil, to_user: nil, until_date: nil, until_time: nil, url: nil, verified_only: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Some parameter documentations has been truncated, see Models::X::TweetGetRepliesParams for more details.

List replies to a tweet

Parameters:

  • id (String)

    Tweet ID to get replies

  • any_words (String)

    Words or quoted phrases where any one can match. Separate with spaces, commas, o

  • cashtags (String)

    Cashtags separated by spaces, commas, or lines.

  • conversation_id (String)

    Conversation ID filter.

  • cursor (String)

    Pagination cursor for tweet replies

  • exact_phrase (String)

    Exact phrase to match.

  • exclude_words (String)

    Words or quoted phrases to exclude. Separate with spaces, commas, or lines.

  • from_user (String)

    Filter by author username.

  • hashtags (String)

    Hashtags separated by spaces, commas, or lines.

  • in_reply_to_tweet_id (String)

    Only replies to this tweet ID.

  • language (String)

    Language code filter, e.g. en or tr.

  • media_type (Symbol, XTwitterScraper::Models::X::TweetGetRepliesParams::MediaType)

    Filter by media type.

  • mentioning (String)

    Filter tweets mentioning a username.

  • min_faves (Integer)

    Minimum likes threshold.

  • min_quotes (Integer)

    Minimum quote count threshold.

  • min_replies (Integer)

    Minimum replies threshold.

  • min_retweets (Integer)

    Minimum retweets threshold.

  • page_size (Integer)

    Maximum items requested from this page (1-100, default 20). The response can con

  • quotes (Symbol, XTwitterScraper::Models::X::TweetGetRepliesParams::Quotes)

    Quote mode.

  • quotes_of_tweet_id (String)

    Only quotes of this tweet ID.

  • replies (Symbol, XTwitterScraper::Models::X::TweetGetRepliesParams::Replies)

    Reply mode.

  • retweets (Symbol, XTwitterScraper::Models::X::TweetGetRepliesParams::Retweets)

    Retweet mode.

  • retweets_of_tweet_id (String)

    Only retweets of this tweet ID.

  • since_date (Date)

    Start date in YYYY-MM-DD format.

  • since_time (String)

    Unix timestamp - return replies posted after this time

  • to_user (String)

    Filter replies sent to a username.

  • until_date (Date)

    End date in YYYY-MM-DD format.

  • until_time (String)

    Unix timestamp - return replies posted before this time

  • url (String)

    URL substring or domain filter.

  • verified_only (Boolean)

    Only return tweets from verified authors.

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 329

def get_replies(id, params = {})
  parsed, options = XTwitterScraper::X::TweetGetRepliesParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/tweets/%1$s/replies", id],
    query: query.transform_keys(
      any_words: "anyWords",
      conversation_id: "conversationId",
      exact_phrase: "exactPhrase",
      exclude_words: "excludeWords",
      from_user: "fromUser",
      in_reply_to_tweet_id: "inReplyToTweetId",
      media_type: "mediaType",
      min_faves: "minFaves",
      min_quotes: "minQuotes",
      min_replies: "minReplies",
      min_retweets: "minRetweets",
      page_size: "pageSize",
      quotes_of_tweet_id: "quotesOfTweetId",
      retweets_of_tweet_id: "retweetsOfTweetId",
      since_date: "sinceDate",
      since_time: "sinceTime",
      to_user: "toUser",
      until_date: "untilDate",
      until_time: "untilTime",
      verified_only: "verifiedOnly"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#get_retweeters(id, cursor: nil, page_size: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Some parameter documentations has been truncated, see Models::X::TweetGetRetweetersParams for more details.

List users who retweeted a tweet

Parameters:

  • id (String)

    Tweet ID to get retweeters

  • cursor (String)

    Pagination cursor for retweeters

  • page_size (Integer)

    Maximum user profiles requested from this page (20-200, default 200). The respon

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



380
381
382
383
384
385
386
387
388
389
390
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 380

def get_retweeters(id, params = {})
  parsed, options = XTwitterScraper::X::TweetGetRetweetersParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/tweets/%1$s/retweeters", id],
    query: query.transform_keys(page_size: "pageSize"),
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#get_thread(id, cursor: nil, page_size: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Some parameter documentations has been truncated, see Models::X::TweetGetThreadParams for more details.

Get full conversation thread for a tweet

Parameters:

  • id (String)

    Tweet ID to get thread context

  • cursor (String)

    Pagination cursor for thread tweets

  • page_size (Integer)

    Maximum items requested from this page (1-100, default 20). The response can con

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



410
411
412
413
414
415
416
417
418
419
420
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 410

def get_thread(id, params = {})
  parsed, options = XTwitterScraper::X::TweetGetThreadParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["x/tweets/%1$s/thread", id],
    query: query.transform_keys(page_size: "pageSize"),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#list(ids:, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get multiple tweets by IDs

Parameters:

Returns:

See Also:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 83

def list(params)
  parsed, options = XTwitterScraper::X::TweetListParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "x/tweets",
    query: query,
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ XTwitterScraper::Models::X::TweetRetrieveResponse

Get tweet with full text, author, metrics and media

Parameters:

Returns:

See Also:



63
64
65
66
67
68
69
70
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 63

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["x/tweets/%1$s", id],
    model: XTwitterScraper::Models::X::TweetRetrieveResponse,
    options: params[:request_options]
  )
end

#search(q:, advanced_query: nil, any_words: nil, bounding_box: nil, cashtags: nil, conversation_id: nil, cursor: nil, exact_phrase: nil, exclude_words: nil, from_user: nil, hashtags: nil, in_reply_to_tweet_id: nil, language: nil, limit: nil, list_id: nil, media_type: nil, mentioning: nil, min_faves: nil, min_quotes: nil, min_replies: nil, min_retweets: nil, place: nil, place_country: nil, point_radius: nil, query_type: nil, quotes: nil, quotes_of_tweet_id: nil, replies: nil, retweets: nil, retweets_of_tweet_id: nil, since_date: nil, since_time: nil, to_user: nil, until_date: nil, until_time: nil, url: nil, verified_only: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Some parameter documentations has been truncated, see Models::X::TweetSearchParams for more details.

Search tweets by query, Tweet ID, X status URL, or account date window

Parameters:

  • q (String)

    Search query (keywords,

  • advanced_query (String)

    Raw advanced search query appended as-is.

  • any_words (String)

    Words or quoted phrases where any one can match. Separate with spaces, commas, o

  • bounding_box (String)

    Geo bounding box, e.g. -74.1 40.6 -73.9 40.8.

  • cashtags (String)

    Cashtags separated by spaces, commas, or lines.

  • conversation_id (String)

    Conversation ID filter.

  • cursor (String)

    Pagination cursor from previous response

  • exact_phrase (String)

    Exact phrase to match.

  • exclude_words (String)

    Words or quoted phrases to exclude. Separate with spaces, commas, or lines.

  • from_user (String)

    Filter by author username.

  • hashtags (String)

    Hashtags separated by spaces, commas, or lines.

  • in_reply_to_tweet_id (String)

    Only replies to this tweet ID.

  • language (String)

    Language code filter, e.g. en or tr.

  • limit (Integer)

    Max tweets to return (server paginates internally). Omit for single page (~20).

  • list_id (String)

    Search within a list ID.

  • media_type (Symbol, XTwitterScraper::Models::X::TweetSearchParams::MediaType)

    Filter by media type.

  • mentioning (String)

    Filter tweets mentioning a username.

  • min_faves (Integer)

    Minimum likes threshold.

  • min_quotes (Integer)

    Minimum quote count threshold.

  • min_replies (Integer)

    Minimum replies threshold.

  • min_retweets (Integer)

    Minimum retweets threshold.

  • place (String)

    Search within a place ID.

  • place_country (String)

    Search within a country code.

  • point_radius (String)

    Geo point radius, e.g. -73.99 40.73 25mi.

  • query_type (Symbol, XTwitterScraper::Models::X::TweetSearchParams::QueryType)

    Sort order - Latest (chronological) or Top (engagement-ranked)

  • quotes (Symbol, XTwitterScraper::Models::X::TweetSearchParams::Quotes)

    Quote mode.

  • quotes_of_tweet_id (String)

    Only quotes of this tweet ID.

  • replies (Symbol, XTwitterScraper::Models::X::TweetSearchParams::Replies)

    Reply mode.

  • retweets (Symbol, XTwitterScraper::Models::X::TweetSearchParams::Retweets)

    Retweet mode.

  • retweets_of_tweet_id (String)

    Only retweets of this tweet ID.

  • since_date (Date)

    Start date in YYYY-MM-DD format.

  • since_time (String)

    ISO 8601 timestamp - only return tweets after this time

  • to_user (String)

    Filter replies sent to a username.

  • until_date (Date)

    End date in YYYY-MM-DD format.

  • until_time (String)

    ISO 8601 timestamp - only return tweets before this time

  • url (String)

    URL substring or domain filter.

  • verified_only (Boolean)

    Only return tweets from verified authors.

  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 508

def search(params)
  parsed, options = XTwitterScraper::X::TweetSearchParams.dump_request(params)
  query = XTwitterScraper::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "x/tweets/search",
    query: query.transform_keys(
      advanced_query: "advancedQuery",
      any_words: "anyWords",
      bounding_box: "boundingBox",
      conversation_id: "conversationId",
      exact_phrase: "exactPhrase",
      exclude_words: "excludeWords",
      from_user: "fromUser",
      in_reply_to_tweet_id: "inReplyToTweetId",
      list_id: "listId",
      media_type: "mediaType",
      min_faves: "minFaves",
      min_quotes: "minQuotes",
      min_replies: "minReplies",
      min_retweets: "minRetweets",
      place_country: "placeCountry",
      point_radius: "pointRadius",
      query_type: "queryType",
      quotes_of_tweet_id: "quotesOfTweetId",
      retweets_of_tweet_id: "retweetsOfTweetId",
      since_date: "sinceDate",
      since_time: "sinceTime",
      to_user: "toUser",
      until_date: "untilDate",
      until_time: "untilTime",
      verified_only: "verifiedOnly"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end