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

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:



295
296
297
298
299
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 295

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:, text:, attachment_url: nil, community_id: nil, is_note_tweet: nil, media_ids: nil, reply_to_tweet_id: nil, request_options: {}) ⇒ XTwitterScraper::Models::X::TweetCreateResponse

Create tweet

Parameters:

  • account (String)

    X account (@username or account ID)

  • text (String)
  • attachment_url (String)
  • community_id (String)
  • is_note_tweet (Boolean)
  • media_ids (Array<String>)
  • reply_to_tweet_id (String)
  • request_options (XTwitterScraper::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



38
39
40
41
42
43
44
45
46
47
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 38

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:



105
106
107
108
109
110
111
112
113
114
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 105

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, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedUsers

Get users who liked a tweet

Parameters:

  • id (String)

    Tweet ID to get favoriters

  • cursor (String)

    Pagination cursor for favoriters

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

Returns:

See Also:



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 129

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,
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

#get_quotes(id, cursor: nil, include_replies: nil, since_time: nil, until_time: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get quote tweets of a tweet

Parameters:

  • id (String)

    Tweet ID to get quotes

  • cursor (String)

    Pagination cursor for quote tweets

  • include_replies (Boolean)

    Include reply quotes (default false)

  • since_time (String)

    Unix timestamp - return quotes posted after this time

  • until_time (String)

    Unix timestamp - return quotes posted before this time

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

Returns:

See Also:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 160

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(
      include_replies: "includeReplies",
      since_time: "sinceTime",
      until_time: "untilTime"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

#get_replies(id, cursor: nil, since_time: nil, until_time: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Get replies to a tweet

Parameters:

  • id (String)

    Tweet ID to get replies

  • cursor (String)

    Pagination cursor for tweet replies

  • since_time (String)

    Unix timestamp - return replies posted after this time

  • until_time (String)

    Unix timestamp - return replies posted before this time

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

Returns:

See Also:



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 193

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(since_time: "sinceTime", until_time: "untilTime"),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

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

Get users who retweeted a tweet

Parameters:

  • id (String)

    Tweet ID to get retweeters

  • cursor (String)

    Pagination cursor for retweeters

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

Returns:

See Also:



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 218

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,
    model: XTwitterScraper::PaginatedUsers,
    options: options
  )
end

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

Get thread context for a tweet

Parameters:

  • id (String)

    Tweet ID to get thread context

  • cursor (String)

    Pagination cursor for thread tweets

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

Returns:

See Also:



243
244
245
246
247
248
249
250
251
252
253
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 243

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,
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end

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

Get multiple tweets by IDs

Parameters:

Returns:

See Also:



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 80

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

Look up tweet

Parameters:

Returns:

See Also:



60
61
62
63
64
65
66
67
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 60

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:, cursor: nil, limit: nil, query_type: nil, since_time: nil, until_time: nil, request_options: {}) ⇒ XTwitterScraper::Models::PaginatedTweets

Search tweets

Parameters:

  • q (String)

    Search query (keywords,

  • cursor (String)

    Pagination cursor from previous response

  • limit (Integer)

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

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

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

  • since_time (String)

    ISO 8601 timestamp — only return tweets after this time

  • until_time (String)

    ISO 8601 timestamp — only return tweets before this time

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

Returns:

See Also:



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/x_twitter_scraper/resources/x/tweets.rb', line 276

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(
      query_type: "queryType",
      since_time: "sinceTime",
      until_time: "untilTime"
    ),
    model: XTwitterScraper::PaginatedTweets,
    options: options
  )
end