tweet_embed: Embed a Tweet in R Markdown HTML outputs

View source: R/tweet.R

tweet_embedR Documentation

Embed a Tweet in R Markdown HTML outputs

Description

Uses Twitter's oembed API to embed a tweet in R Markdown HTML outputs.

Usage

tweet_embed(
  tweet_url,
  maxwidth = 550,
  plain = FALSE,
  hide_media = FALSE,
  hide_thread = FALSE,
  omit_script = TRUE,
  align = c("none", "left", "right", "center"),
  related = NULL,
  lang = "en",
  theme = c("light", "dark"),
  link_color = NULL,
  widget_type = NULL,
  dnt = TRUE
)

tweet_url(screen_name = NULL, status_id)

screen_name %tweet% status_id

Arguments

tweet_url

The URL for the tweet, or use tweet_url() to build the URL from a screen_name and status_id.

maxwidth

The maximum width of a rendered Tweet in whole pixels. A supplied value under or over the allowed range will be returned as the minimum or maximum supported width respectively; the reset width value will be reflected in the returned width property. Note that Twitter does not support the oEmbed maxheight parameter. Tweets are fundamentally text, and are therefore of unpredictable height that cannot be scaled like an image or video. Relatedly, the oEmbed response will not provide a value for height. Implementations that need consistent heights for Tweets should refer to the hide_thread and 'hide_media“ parameters below.

plain

Embeds the tweet without including Twitter's JavaScript code. This means the tweets will be displayed as minimally styled HTML in tweet_embed() or tweet_screenshot(). In include_tweet(), plain = TRUE will convert the tweet text into markdown for non-HTML outputs.

Note that for HTML outputs, you can't selectively choose whether or not a tweet is rendered in plain HTML if you include multiple tweet. Including one rich embedded tweet will trigger rich embedding of all tweets loaded on the page.

hide_media

When set to true, "t", or 1 links in a Tweet are not expanded to photo, video, or link previews.

hide_thread

When set to true, "t", or 1 a collapsed version of the previous Tweet in a conversation thread will not be displayed when the requested Tweet is in reply to another Tweet.

omit_script

When set to FALSE, Twitter's remote script responsible for loading the Tweet widget will be used. Otherwise, the script included by this package will be used. If you are including multiple tweets on a page, it is recommended to use the default FALSE.

align

Specifies whether the embedded Tweet should be floated left, right, or center in the page relative to the parent element.

related

A comma-separated list of Twitter usernames related to your content. This value will be forwarded to Tweet action intents if a viewer chooses to reply, like, or retweet the embedded Tweet.

lang

Request returned HTML and a rendered Tweet in the specified Twitter language supported by embedded Tweets.

theme

When set to dark, the Tweet is displayed with light text over a dark background.

link_color

Adjust the color of Tweet text links with a hexadecimal color value.

widget_type

Set to video to return a Twitter Video embed for the given Tweet.

dnt

When set to true, the Tweet and its embedded page on your site are not used for purposes that include personalized suggestions and personalized ads.

screen_name

The user's screen name

status_id

The tweet's status id

Value

The placeholder HTML for the tweet

Functions

  • tweet_url: Create a URL for a tweet from a screen name and status id.

  • %tweet%: A shortcut for the impatient.

References

https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed

See Also

Other Tweet-embedding functions: include_tweet(), tweet_screenshot()

Examples

## Not run: 
# these are equivalent
tweet_embed("https://twitter.com/alexpghayes/status/1211748406730706944")

tweet_embed(tweet_url("alexpghayes", "1211748406730706944"))

tweet_embed("1211748406730706944")

# Adding many tweets at once to a document takes a little bit more work
thread <- c(
  "https://twitter.com/grrrck/status/1333804309272621060",
  "https://twitter.com/grrrck/status/1333804487148855300",
  "https://twitter.com/grrrck/status/1333805092152123394"
)

htmltools::tagList(
  lapply(thread, tweet_embed, plain = TRUE)
)

## End(Not run)


gadenbuie/tweetrmd documentation built on Feb. 3, 2023, 1:35 p.m.