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:



568
569
570
571
572
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 568

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)



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

def like
  @like
end

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

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



17
18
19
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 17

def retweet
  @retweet
end

Instance Method Details

#create(account:, idempotency_key:, 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)

    Body param: X account (@username or account ID)

  • idempotency_key (String)

    Header param: Generate one unique value for each intended write. Reuse it only w

  • community_id (String)

    Body param

  • is_note_tweet (Boolean)

    Body param

  • media (Array<String>)

    Body param: Array of public media URLs to attach. Supports up to 4 images or exa

  • reply_to_tweet_id (String)

    Body param

  • text (String)

    Body param: Tweet text (optional when media is provided)

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

Returns:

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 45

def create(params)
  parsed, options = XTwitterScraper::X::TweetCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "x/tweets",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: XTwitterScraper::Models::X::TweetCreateResponse,
    options: options
  )
end

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

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

Delete tweet

Parameters:

  • id (String)

    Path param: Tweet ID to delete

  • account (String)

    Body param: X account identifier (@username or account ID)

  • idempotency_key (String)

    Header param: Generate one unique value for each intended write. Reuse it only w

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

Returns:

See Also:



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 119

def delete(id, params)
  parsed, options = XTwitterScraper::X::TweetDeleteParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :delete,
    path: ["x/tweets/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    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.

Returns liker profiles that X makes visible for the post. X can withhold liker identities even when the post reports likes. In that case this endpoint returns 424 favoriters_unavailable instead of a misleading empty success.

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:



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 152

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:



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 238

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.

Returns visible replies. For an unfiltered first page, Xquik compares a terminal page with the post's reported reply count. If the page is visibly incomplete, the endpoint returns 424 replies_incomplete instead of presenting partial coverage as complete. Use tweet search with a conversation_id:{id} query as the broader fallback.

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:



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 348

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:



399
400
401
402
403
404
405
406
407
408
409
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 399

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:



429
430
431
432
433
434
435
436
437
438
439
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 429

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:



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 89

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 & media

Parameters:

Returns:

See Also:



69
70
71
72
73
74
75
76
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 69

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:



527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 527

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