Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Twitter Oembed

Twitter Oembed Laravel Package

spatie/twitter-oembed

Fetch Twitter (X) tweet embed HTML via the public oEmbed API—no developer account needed. Lightweight utility for turning tweet URLs into embeddable HTML for blogs, markdown, editors, or emails, without relying on Twitter’s heavy JavaScript widget.

View on GitHub
Deep Wiki
Context7

Retrieve tweets with the Twitter oEmbed API

Frequently asked questions about Twitter Oembed
How do I install spatie/twitter-oembed in a Laravel project?
Run `composer require spatie/twitter-oembed` in your project directory. The package integrates seamlessly with Laravel’s service container and requires no additional configuration unless you customize caching or HTTP clients.
Does this package work with Laravel 10/11? What’s the supported PHP version?
Yes, the package supports Laravel 10 and 11 and requires PHP 8.1 or higher. Check the [GitHub repository](https://github.com/spatie/twitter-oembed) for the latest compatibility updates, as Spatie regularly aligns with newer Laravel releases.
Can I use this to embed tweets in a Laravel Blade template?
Absolutely. Fetch the embed HTML via the package’s `getEmbedHtml()` method, then output it directly in your Blade view. For example: `{{ $tweetEmbed->getEmbedHtml() }}`. Ensure you sanitize the HTML to prevent XSS if embedding user-generated content.
What happens if Twitter’s oEmbed API is down or rate-limited?
The package doesn’t include built-in retry logic or fallback mechanisms. You’ll need to implement caching (e.g., Redis) with a short TTL (e.g., 5 minutes) and handle failures gracefully, such as displaying a cached version or a placeholder.
Does this package support quoted tweets or replies?
No, the oEmbed API (and thus this package) only returns basic tweet data like text, author, and timestamp. Quoted tweets or replies require Twitter’s full API, which needs authentication. For richer data, consider pairing this with `spatie/twitter-api`.
How do I cache tweet embeds to reduce API calls?
Use Laravel’s cache system (e.g., Redis or file cache) to store responses. The package doesn’t enforce caching, but you can wrap its methods in a cached closure or use Laravel’s `Cache::remember()` to store embed HTML for a set duration.
Is this package suitable for newsletters or email templates?
Yes, it’s ideal for static email content like newsletters. Fetch the embed HTML server-side and include it directly in your email template. However, test rendering in your email client to ensure compatibility, as some may strip or modify embedded HTML.
Can I use this in a headless CMS like Strapi or directus?
Yes, the package is framework-agnostic and works in any PHP environment. For a headless CMS, fetch embeds during content creation or updates, then store the HTML in your database to avoid repeated API calls.
What’s the difference between this and Twitter’s official embed widget?
This package generates static HTML via Twitter’s oEmbed API, avoiding JavaScript dependencies. The official widget is interactive (likes, replies) but requires Twitter’s script and may break if Twitter changes its embed code. Choose this for static content, the widget for dynamic interactions.
How do I handle XSS risks from embedded tweet HTML?
Always sanitize the embed HTML before rendering. Use Laravel’s `Str::markdown()` or a library like `htmlpurifier` to strip unsafe tags. Avoid embedding tweets from untrusted sources, as the oEmbed API doesn’t validate content.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport