Drupal has had the ability to use oEmbed in core since version 8.6.0. It was included along with the other media changes that went into core in that version.
I have used some of the Drupal core oEmbed functionality to include YouTube videos into content, but I’ve never dug deeper to see what else I could do with it. Although Drupal comes with Vimeo and YouTube services available there are many more services to include, you just need to enable them.
In this article I will show what oEmbed is, how to use it out of the box, and then how to add more services to your system.
First, let’s cover some groundwork and address what oEmbed is.
What is oEmbed?
oEmbed is a standard that allows a client to ask a service for information on how to embed a resource. Essentially a website will expose a service that you can call to get information on what markup to create in order to embed that item; including some metadata about that resource. This means that you don’t need to sign into a complex API, or scrape content from a page, it’s all handed to you.
A good example is YouTube, since that is well understood and built into Drupal’s default oEmbed providers. Take the following URL of a video on the YouTube.
https://www.youtube.com/watch?v=uzRQ93UEOe0
You would ask YouTube for information on how to embed that video using the YouTube oEmbed service.
https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=uzRQ93UEOe0
YouTube responds with a JSON response containing information about that video, including title, duration, dimensions, a thumbnail image and the code used to embed that video.