Class: XTwitterScraper::Resources::X::Media

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

Overview

Media upload and download

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Media

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 Media.

Parameters:



64
65
66
# File 'lib/x_twitter_scraper/resources/x/media.rb', line 64

def initialize(client:)
  @client = client
end

Instance Method Details

#download(tweet_id: nil, tweet_ids: nil, tweet_input: nil, tweet_url: nil, request_options: {}) ⇒ XTwitterScraper::Models::X::MediaDownloadResponse

Download images and videos from tweets

Parameters:

  • tweet_id (String)

    Numeric tweet ID alias for tweetInput

  • tweet_ids (Array<String>)

    Array of tweet URLs or IDs (bulk, max 50 string items)

  • tweet_input (String)

    Tweet URL or ID (single tweet)

  • tweet_url (String)

    Tweet URL alias for tweetInput

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

Returns:

See Also:



25
26
27
28
29
30
31
32
33
34
# File 'lib/x_twitter_scraper/resources/x/media.rb', line 25

def download(params = {})
  parsed, options = XTwitterScraper::X::MediaDownloadParams.dump_request(params)
  @client.request(
    method: :post,
    path: "x/media/download",
    body: parsed,
    model: XTwitterScraper::Models::X::MediaDownloadResponse,
    options: options
  )
end

#upload(account:, url:, request_options: {}) ⇒ XTwitterScraper::Models::X::MediaUploadResponse

Upload media

Parameters:

  • account (String)

    X account (@username or ID) uploading media from URL

  • url (String)

    HTTPS URL to download and upload as media

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

Returns:

See Also:



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/x_twitter_scraper/resources/x/media.rb', line 49

def upload(params)
  parsed, options = XTwitterScraper::X::MediaUploadParams.dump_request(params)
  @client.request(
    method: :post,
    path: "x/media",
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: XTwitterScraper::Models::X::MediaUploadResponse,
    options: options
  )
end