spatie/twitter-oembed

Retrieve tweets with the Twitter oEmbed API

Fund package maintenance!
spatie

dev-main 2022-03-21 14:43 UTC

This package is auto-updated.

Last update: 2024-11-21 20:19:17 UTC


README

Retrieve tweets with the Twitter oEmbed API

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A utility package to retrieve tweets with Twitter's oEmbed API. The main benefit of Twitter's oEmbed API is that it's public. You don't need to set up a developer account to get started, but the data in the response is minimal.

This package is meant to set the stage for tools that embed Tweets. For example, a markdown plugin that embeds tweets as static HTML so your blog doesn't need a bloated JavaScript widget. Or a rich text editor plugin for your email platform so tweets can be embedded in newsletters, like Substack does.

It's still in an experimental stage, I'm not sure what direction this is going to go yet. I don't think it's valuable enough as long as it doesn't support displaying basic data like an image or quoted tweet, which the oEmbed API doesn't return by default.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/twitter-oembed

Usage

$tweet = (new TwitterOEmbed())->embed(
    'https://twitter.com/AoDespair/status/1173718972103090177'
);

echo $tweet->url;
// "https://twitter.com/AoDespair/status/1173718972103090177"

echo $tweet->name;
// "David Simon"

echo $tweet->username;
// "@AoDespair"

echo $tweet->html;
// "<p>Have I seen The Wire?</p>"

echo $tweet->date;
// 2019-09-16

Alternatives

  • j7mbo/twitter-api-php: A Twitter API wrapper. This returns a lot more data, but requires a developer account.
  • embed/embed: A generic oEmbed package. This supports retrieving oEmbed data from any source, like YouTube or Wikipedia. spatie/twitter-oembed aims to add Twitter specific features like parsing the tweet's date and author metadata.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.