A while ago I wrote about including oEmbed providers in a Drupal site and briefly touched upon creating custom providers. I didn’t go into any more detail there so I decided to write another article looking at creating custom oEmbed providers.
In this article I will cover what oEmbed is and how to set up a custom oEmbed endpoint. I will also then go onto show how to setup and configure a Drupal site to consume that custom oEmbed endpoint.
What Is oEmbed?
oEmbed is a specification that allows websites to share content through the use of an API. This allows users to share a URL for a web page and see a representation of that page embedded in any site. Using this technique allows for videos and images to be shared between sites easily, without the user having to worry about image dimensions or generating thumbnails.
It’s up to the oEmbed provider to decide on what sort of content they will publish as part of an oEmbed request. The response will have a ‘type’ parameter that can be “photo”, “video”, “link” or “rich” (which is essentially just HTML), each of which will return different parameters depending on what is needed. You can see the full specification of oEmbed on the oembed.com website.
As it is possible for third party sites to add pretty much anything to the response there are some security considerations to be taken into account. The oEmbed group maintains a list of available providers (seen at https://oembed.com/providers.json) that you are recommended to adhere to. It is also recommended that all embedded content is done as an iframe element to prevent anything within the iframe leaking out into the rest of the page.