Module: Twitter::REST::Media

Included in:
API
Defined in:
lib/twitter/rest/media.rb

Instance Method Summary (collapse)

Instance Method Details

- (Integer) upload(media, options = {})

Uploads media to attach to a tweet

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



17
18
19
20
21
22
23
24
25
26
# File 'lib/twitter/rest/media.rb', line 17

def upload(media, options = {})
  fail(Twitter::Error::UnacceptableIO.new) unless media.respond_to?(:to_io)
  url_prefix = 'https://upload.twitter.com'
  path = '/1.1/media/upload.json'
  conn = connection.dup
  conn.url_prefix = url_prefix
  headers = request_headers(:post, url_prefix + path, options)
  options.merge!(:media => media)
  conn.post(path, options) { |request| request.headers.update(headers) }.env.body[:media_id]
end