You can use the Threads oEmbed endpoint to retrieve the embed HTML code snippet and essential metadata for a public Threads post, allowing you to render and display a rich preview of the post on an external website or application. Text, image, video, and carousel posts are supported.
You can fetch the embed HTML code programmatically via the API or from threads.com by clicking on a post's share icon and selecting the "Get embed code" button.
To get a Threads post's embed HTML code using the API, send a request to the /oembed endpoint:
GET /oembed?url=<URL_OF_THE_POST>
URL_OF_THE_POST — The permalink of the Threads post that you want to query.Upon success, the API will respond with a JSON object containing the post's embed HTML code and additional metadata. The embed HTML code will be in the returned html field.
Refer to the Threads oEmbed reference for a list of query string parameters you can include to augment the request.
curl -X GET \ "https://graph.threads.net/v1.0/oembed?url=<URL_OF_THE_POST>"
Default fields that are returned:
{
"type": "rich",
"version": "1.0",
"html": "<blockquote class=\"text-post-media\" data-text-post-permalink=...",
"provider_name": "Threads",
"provider_url": "https://www.threads.com/",
"width": 658
}
The url query string parameter accepts the following URL formats:
https://www.threads.com/@{username}/post/{media-shortcode}/
https://www.threads.com/t/{media-shortcode}/
The embed HTML contains a reference to the Threads embed.js JavaScript library. When the library loads, it scans the page for the post HTML and generates the fully rendered post.
<script async src="https://www.threads.com/embed.js"></script>
The embedded post is responsive and will adapt to the size of its container. This means that the height will vary depending on the container width and the length of the post content. You can set the maximum width by including the maxwidth query string parameter in your request.
Note: The maxwidth must be between 320 and 658 pixels.