View Source Tw.V1_1.Media (Tw v0.1.1)
Media data structure and related functions.
https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities
Link to this section Summary
Types
field description display_url
URL of the media to display to clients. Example: "pic.twitter.com/rJC5Pxsu"
.expanded_url
An expanded version of display_url. Links to the media display page. Example: "http://twitter.com/yunorno/status/114080493036773378/photo/1"
.id
ID of the media expressed as a 64-bit integer. Example: 114080493040967680
.id_str
ID of the media expressed as a string. Example: "114080493040967680"
.indices
An array of integers indicating the offsets within the Tweet text where the URL begins and ends. The first integer represents the location of the first character of the URL in the Tweet text. The second integer represents the location of the first non-URL character occurring after the URL (or the end of the string if the URL is the last part of the Tweet text). Example: [15,35]
.media_url
An http:// URL pointing directly to the uploaded media file. Example: "http://pbs.twimg.com/media/DOhM30VVwAEpIHq.jpg" For media in direct messages, media_url is the same https URL as media_url_https and must be accessed by signing a request with the user’s access token using OAuth 1.0A.It is not possible to access images via an authenticated twitter.com session. Please visit this page to learn how to account for these recent change. You cannot directly embed these images in a web page.See Photo Media URL formatting for how to format a photo's URL, such as media_url_https, based on the available sizes.
.media_url_https
An https:// URL pointing directly to the uploaded media file, for embedding on https pages. Example: "https://p.twimg.com/AZVLmp-CIAAbkyy.jpg" For media in direct messages, media_url_https must be accessed by signing a request with the user’s access token using OAuth 1.0A.It is not possible to access images via an authenticated twitter.com session. Please visit this page to learn how to account for these recent change. You cannot directly embed these images in a web page.See Photo Media URL formatting for how to format a photo's URL, such as media_url_https, based on the available sizes.
.sizes
An object showing available sizes for the media file. source_status_id
Nullable. For Tweets containing media that was originally associated with a different tweet, this ID points to the original Tweet. Example: 205282515685081088
.source_status_id_str
Nullable. For Tweets containing media that was originally associated with a different tweet, this string-based ID points to the original Tweet. Example: "205282515685081088"
.type
Type of uploaded media. Possible types include photo, video, and animated_gif. Example: "photo"
.url
Wrapped URL for the media link. This corresponds with the URL embedded directly into the raw Tweet text, and the values for the indices parameter. Example: "http://t.co/rJC5Pxsu"
.
Functions
Bind subtitles to an uploaded video by requesting POST media/subtitles/create
.
Add metadata to an uploaded medium by POST media/metadata/create
Decode JSON-decoded map into t/0
Unbind subtitles to an uploaded video by requesting POST media/subtitles/delete
.
Upload an image or video to Twitter by senqunce of requests to POST media/upload
and GET media/upload
.
If you want to use more low-level API, use upload_command/3
instead.
Link to this section Types
Specs
bind_subtitles_params() :: %{ media_id: id(), subtitles: [ %{ media_id: binary() | pos_integer(), language_code: binary(), display_name: binary() } ] }
Specs
Specs
id() :: pos_integer()
Specs
t() :: %Tw.V1_1.Media{ display_url: binary(), expanded_url: binary(), id: id(), id_str: binary(), indices: [non_neg_integer()], media_url: binary(), media_url_https: binary(), sizes: Tw.V1_1.Sizes.t(), source_status_id: Tw.V1_1.Tweet.id() | nil, source_status_id_str: Tw.V1_1.Tweet.id() | nil, type: binary(), url: binary() }
field description display_url
URL of the media to display to clients. Example: "pic.twitter.com/rJC5Pxsu"
.expanded_url
An expanded version of display_url. Links to the media display page. Example: "http://twitter.com/yunorno/status/114080493036773378/photo/1"
.id
ID of the media expressed as a 64-bit integer. Example: 114080493040967680
.id_str
ID of the media expressed as a string. Example: "114080493040967680"
.indices
An array of integers indicating the offsets within the Tweet text where the URL begins and ends. The first integer represents the location of the first character of the URL in the Tweet text. The second integer represents the location of the first non-URL character occurring after the URL (or the end of the string if the URL is the last part of the Tweet text). Example: [15,35]
.media_url
An http:// URL pointing directly to the uploaded media file. Example: "http://pbs.twimg.com/media/DOhM30VVwAEpIHq.jpg" For media in direct messages, media_url is the same https URL as media_url_https and must be accessed by signing a request with the user’s access token using OAuth 1.0A.It is not possible to access images via an authenticated twitter.com session. Please visit this page to learn how to account for these recent change. You cannot directly embed these images in a web page.See Photo Media URL formatting for how to format a photo's URL, such as media_url_https, based on the available sizes.
.media_url_https
An https:// URL pointing directly to the uploaded media file, for embedding on https pages. Example: "https://p.twimg.com/AZVLmp-CIAAbkyy.jpg" For media in direct messages, media_url_https must be accessed by signing a request with the user’s access token using OAuth 1.0A.It is not possible to access images via an authenticated twitter.com session. Please visit this page to learn how to account for these recent change. You cannot directly embed these images in a web page.See Photo Media URL formatting for how to format a photo's URL, such as media_url_https, based on the available sizes.
.sizes
An object showing available sizes for the media file. source_status_id
Nullable. For Tweets containing media that was originally associated with a different tweet, this ID points to the original Tweet. Example: 205282515685081088
.source_status_id_str
Nullable. For Tweets containing media that was originally associated with a different tweet, this string-based ID points to the original Tweet. Example: "205282515685081088"
.type
Type of uploaded media. Possible types include photo, video, and animated_gif. Example: "photo"
.url
Wrapped URL for the media link. This corresponds with the URL embedded directly into the raw Tweet text, and the values for the indices parameter. Example: "http://t.co/rJC5Pxsu"
.
Specs
Specs
upload_append_command_params() :: %{ :command => :APPEND, :media_id => pos_integer(), :media => binary(), :segment_index => binary(), optional(:additional_owners) => [Tw.V1_1.User.id()] } | %{ :command => :APPEND, :media_id => pos_integer(), :media_data => binary(), :segment_index => binary(), optional(:additional_owners) => [Tw.V1_1.User.id()] }
Specs
upload_command_params() :: upload_init_command_params() | upload_append_command_params() | upload_finalize_command_params() | upload_status_command_params()
Specs
Specs
upload_finalize_command_params() :: %{ command: :FINALIZE, media_id: pos_integer() }
Specs
upload_init_command_params() :: %{ :command => :INIT, :total_bytes => non_neg_integer(), :media_type => binary(), optional(:media_category) => binary(), optional(:additional_owners) => [Tw.V1_1.User.id()] }
Specs
upload_ok_result() :: %{ media_id: id(), media_id_string: binary(), expires_after_secs: pos_integer() }
Specs
upload_params() :: %{ :path => Path.t(), optional(:media_category) => binary(), optional(:additional_owners) => [pos_integer()] } | %{ :device => IO.device(), :media_type => binary(), :total_bytes => pos_integer(), optional(:media_category) => binary(), optional(:additional_owners) => [pos_integer()] } | %{ :data => iodata(), :media_type => binary(), optional(:media_category) => binary(), optional(:additional_owners) => [pos_integer()] }
Specs
upload_status_command_params() :: %{command: :STATUS, media_id: pos_integer()}
Link to this section Functions
Specs
bind_subtitles(Tw.V1_1.Client.t(), bind_subtitles_params()) :: {:ok, nil} | {:error, Tw.V1_1.Client.error()}
Bind subtitles to an uploaded video by requesting POST media/subtitles/create
.
You can associate subtitles to video before or after Tweeting.
See the Twitter API documentation for details.
Examples
iex> {:ok, video} = Tw.V1_1.Media.upload(client, %{path: "/tmp/abc.mp4"})
iex> {:ok, en_sub} = Tw.V1_1.Media.upload(client, %{path: "/tmp/en.srt"})
iex> subtitles = [%{media_id: en_sub.media_id, language_code: "EN", display_name: "English"}]
iex> {:ok, en_sub} = Tw.V1_1.Media.bind_subtitles(client, %{media_id: video.media_id, subtitles: subtitles})
{:ok, nil}
Specs
create_metadata(Tw.V1_1.Client.t(), create_metadata_params()) :: {:ok, binary()} | {:error, Tw.V1_1.Client.error()}
Add metadata to an uploaded medium by POST media/metadata/create
This endpoint can be used to provide additional information about the uploaded media_id. This feature is currently only supported for images and GIFs.
See the Twitter API documentation for details.
Examples
iex> {:ok, res} = Tw.V1_1.Media.upload(client, %{path: "/tmp/abc.png"})
iex> Tw.V1_1.Media.create_metadata(client, %{media_id: res.media_id, alt_text: %{text: "dancing cat"}})
{:ok, ""}
Specs
Decode JSON-decoded map into t/0
Specs
unbind_subtitles(Tw.V1_1.Client.t(), unbind_subtitles_params()) :: {:ok, nil} | {:error, Tw.V1_1.Client.error()}
Unbind subtitles to an uploaded video by requesting POST media/subtitles/delete
.
You can dissociate subtitles from a video before or after Tweeting.
See the Twitter API documentation for details.
Examples
iex> {:ok, en_sub} = Tw.V1_1.Media.unbind_subtitles(client, %{media_id: video.media_id, subtitles: [%{language_code: "EN"}]})
{:ok, nil}
Specs
upload(Tw.V1_1.Client.t(), upload_params()) :: {:ok, upload_ok_result()} | {:error, :file.posix() | Tw.V1_1.Client.error() | upload_error_result()}
Upload an image or video to Twitter by senqunce of requests to POST media/upload
and GET media/upload
.
If you want to use more low-level API, use upload_command/3
instead.
Examples
iex> {:ok, res} = Tw.V1_1.Media.upload(client, %{path: "/tmp/abc.png"})
iex> Tw.V1_1.Tweet.create(client, %{status: "Tweets with a image", media_ids: [res.media_id]})
{:ok, %Tw.V1_1.Tweet{}}
iex> {:ok, res} = Tw.V1_1.Media.upload(client, %{data: png_binary, media_type: "image/png"})
iex> Tw.V1_1.Tweet.create(client, %{status: "Tweets with a image", media_ids: [res.media_id]})
{:ok, %Tw.V1_1.Tweet{}}
See the Twitter API documentation for details.
Specs
upload_command(Tw.V1_1.Client.t(), :get | :post, upload_command_params()) :: {:ok, %{required(atom()) => term()}} | {:error, term()}