View Source Tw.V1_1.Media (Tw v0.1.0)

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

t()
fielddescription
display_urlURL of the media to display to clients. Example: "pic.twitter.com/rJC5Pxsu".
expanded_urlAn expanded version of display_url. Links to the media display page. Example: "http://twitter.com/yunorno/status/114080493036773378/photo/1".
idID of the media expressed as a 64-bit integer. Example: 114080493040967680.
id_strID of the media expressed as a string. Example: "114080493040967680".
indicesAn 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_urlAn 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_httpsAn 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..
sizesAn object showing available sizes for the media file.
source_status_idNullable. For Tweets containing media that was originally associated with a different tweet, this ID points to the original Tweet. Example: 205282515685081088.
source_status_id_strNullable. For Tweets containing media that was originally associated with a different tweet, this string-based ID points to the original Tweet. Example: "205282515685081088".
typeType of uploaded media. Possible types include photo, video, and animated_gif. Example: "photo".
urlWrapped 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

Link to this type

bind_subtitles_params()

View Source

Specs

bind_subtitles_params() :: %{
  media_id: id(),
  subtitles: [
    %{
      media_id: binary() | pos_integer(),
      language_code: binary(),
      display_name: binary()
    }
  ]
}
Link to this type

create_metadata_params()

View Source

Specs

create_metadata_params() :: %{media_id: id(), alt_text: %{text: binary()}}

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()
}
fielddescription
display_urlURL of the media to display to clients. Example: "pic.twitter.com/rJC5Pxsu".
expanded_urlAn expanded version of display_url. Links to the media display page. Example: "http://twitter.com/yunorno/status/114080493036773378/photo/1".
idID of the media expressed as a 64-bit integer. Example: 114080493040967680.
id_strID of the media expressed as a string. Example: "114080493040967680".
indicesAn 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_urlAn 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_httpsAn 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..
sizesAn object showing available sizes for the media file.
source_status_idNullable. For Tweets containing media that was originally associated with a different tweet, this ID points to the original Tweet. Example: 205282515685081088.
source_status_id_strNullable. For Tweets containing media that was originally associated with a different tweet, this string-based ID points to the original Tweet. Example: "205282515685081088".
typeType of uploaded media. Possible types include photo, video, and animated_gif. Example: "photo".
urlWrapped 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".
Link to this type

unbind_subtitles_params()

View Source

Specs

unbind_subtitles_params() :: %{
  media_id: id(),
  subtitles: [%{language_code: binary()}]
}
Link to this type

upload_append_command_params()

View Source

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()]
    }
Link to this type

upload_command_params()

View Source

Specs

Specs

upload_error_result() :: %{
  media_id: id(),
  media_id_string: binary(),
  processing_info: %{
    state: binary(),
    error: %{code: integer(), name: binary(), message: binary()}
  }
}
Link to this type

upload_finalize_command_params()

View Source

Specs

upload_finalize_command_params() :: %{
  command: :FINALIZE,
  media_id: pos_integer()
}
Link to this type

upload_init_command_params()

View Source

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()]
    }
Link to this type

upload_status_command_params()

View Source

Specs

upload_status_command_params() :: %{command: :STATUS, media_id: pos_integer()}

Link to this section Functions

Link to this function

bind_subtitles(client, map)

View Source

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}
Link to this function

create_metadata(client, params)

View Source

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!(map()) :: t()

Decode JSON-decoded map into t/0

Link to this function

unbind_subtitles(client, map)

View Source

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

Link to this function

upload_command(client, method, params)

View Source

Specs

upload_command(Tw.V1_1.Client.t(), :get | :post, upload_command_params()) ::
  {:ok, %{required(atom()) => term()}} | {:error, term()}