Posts from January 2009

Embedding third-party content in your site using oEmbed

There's a whole class of 'Web 2.0' technologies that have emerged recently which have some common features: They solve a simple problem, they do so in a decentralised way and they stay simple. As examples I'd quote things like XFN, OpenID, oAuth and even things like RSS and Atom feeds. They start off by solving a particular use case, and stay as simple as possible (or at least should - I'm looking at you OpenID).

The latest such technology to interest me is oEmbed, via a blog post by Ben Ward. The name is a bit cryptic, but the use case it addresses is one of embedding content from one site into another. That may sound like something esoteric, but just looking back over the handful of blog posts I've done on this very site, a large number of them contain images from Flickr. Looking around the web as a whole people are constantly embedding videos and images from sites all around the web into their forums, blog posts and CMSes.

There are a couple of ways this is normally done in the wild, neither of which are that satisfactory.

  1. The site the content is hosted on generates a snippet of HTML - From looking at a page with the content on, a couple of clicks will give the user some HTML that they can copy and paste into their HTML editor. This is ok for people who are happy with HTML and actually have the ability to edit the HTML in their posts rather than using some sort of WYSIWYG, but can be confusing for novice users. This technique also limits the ability of the receiving site to reformat the content to fit into any existing templating.
  2. The site the content is hosted on gets screen-scraped - Some blogging platforms and CMSes know how major sites like Flickr or YouTube structure their HTML so are able to extract images and videos from just a URL. This of course falls down if the HTML changes significantly, and if you're trying to post content from a site your platform doesn't know about, you're out of luck.

Of the two existing solutions, the second has the best user story. The user clicks an button, pastes in a URL to the content on another site, and the patform slurps up the content, reformats it to fit in with any house styles and inserts it into the content area. What's needed is a way to do this in a decentralised way, which is where oEmbed comes in.

How oEmbed works