oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.The best example of oEmbed can be Facebook’s status update feature. When you paste a youtube movie link in Facebook’s status bar, it automatically identify the link content as youtube movie and embed it in the status. Similarly you can paste any kind of content link: Flickr, Wikipedia etc.
and the provider, in this case Flickr will send response in JSON format:Code language: HTML, XML (xml)http://www.flickr.com/services/oembed/?url=http%3A//www.flickr.com/photos/bees/2341623661/
Youtube example: Request URL:Code language: HTML, XML (xml){ "version": "1.0", "type": "photo", "width": 240, "height": 160, "title": "ZB8T0193", "url": "http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg", "author_name": "Bees", "author_url": "http://www.flickr.com/photos/bees/", "provider_name": "Flickr", "provider_url": "http://www.flickr.com/" }
Response:Code language: HTML, XML (xml)http://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3DM3r2XDceM6A&format=json
{
"version": "1.0",
"type": "video",
"provider_name": "YouTube",
"provider_url": "http://youtube.com/",
"width": 425,
"height": 344,
"title": "Amazing Nintendo Facts",
"author_name": "ZackScott",
"author_url": "http://www.youtube.com/user/ZackScott",
"html":
"<object width=\"425\" height=\"344\">
<param name=\"movie\" value=\"http://www.youtube.com/v/M3r2XDceM6A&fs=1\"></param>
<param name=\"allowFullScreen\" value=\"true\"></param>
<param name=\"allowscriptaccess\" value=\"always\"></param>
<embed src=\"http://www.youtube.com/v/M3r2XDceM6A&fs=1\"
type=\"application/x-shockwave-flash\" width=\"425\" height=\"344\"
allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>
</object>",
}
Code language: HTML, XML (xml)
Once the consumer get the response, all it has to do is to utilize the content and embed it in the page. <link rel="alternate" type="application/json+oembed"
href="http://flickr.com/services/oembed?url=http%3A//flickr.com/photos/bees/2362225867/&format=json"
title="Bacon Lollys oEmbed Profile" />
<link rel="alternate" type="text/xml+oembed"
href="http://flickr.com/services/oembed?url=http%3A//flickr.com/photos/bees/2362225867/&format=xml"
title="Bacon Lollys oEmbed Profile" />
Code language: HTML, XML (xml)
The URLs contained within the href attribute should be the full oEmebed endpoint plus URL and any needed format parameter. No other request parameters should be included in this URL. The type attribute must contain either application/json+oembed for JSON responses, or text/xml+oembed for XML. Content URL:
<input type="text" id="update"/><button id="btn">Get</button>
<div id="embed"></div>
Code language: HTML, XML (xml)
The jQuery Code $(function(){
$('#btn').click(function() {
$("#embed").oembed($('#update').val());
});
});
Code language: JavaScript (javascript)
Don’t forget to include jquery library and jquery oembed javascript in the demo. The Demo Enter any oEmbed supporting URL (Youtube video link or Flickr link http://www.flickr.com/photos/stuckincustoms/2035748576/) in below textbox and press Get. $manager = ProviderManager::getInstance();
$obj=$manager->provide("http://www.youtube.com/watch? v=EQqJSAOOmGI","object");
$html=$obj->renderClass();
Code language: PHP (php)
Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
Hi, nice post!
do you know if Facebook supports oEmbed for all websites? or only for trusted ones like youtube and flickr?
thanks
Hi,
thanks for the post. I think you have a small problem in it: while copying text from http://www.oembed.com/, you have "type (required): The resource type. Valid values, along with value-specific parameters, are described below." - but no "below" is present.
cheers
HEY BRO THIS IS AWESOME BUT CAN U UPLAD AN EXAMPLE ON PHP FOR DOWLOAD?
Hello there! This post couldn't be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this write-up to him. Pretty sure he will have a good read. Thanks for sharing!
Hi,
Good info. Thanks. I am wondering something, maybe you can help me to understand. I have implemented a custom oEmbed provider for one of my applications and it worked like a charm. That's ok. But now, what I wanted to do is to get a list of all these websites (referrers) who are using the oEmbed feature.
What would you suggest in order to get such information?
I was wondering a few possible solutions:
a) Track it using Google Analytics or Piwik, but since the output is following the oEmbed standard, I don't think this will possible. Moreover, I'd need to consume their APIs in order to see what external websites are using it.
b) Keep a simple table in my database with fields such as id, domain, url and date created to keep track of all these calls from external websites. However, since the caller may call oEmbed get method on the provider every time, this may not be the best solution.
In other words, I just need to know the first time that a caller will use oEmbed from an external website but not all the times. Any help on this will be strongly appreciated. Thanks!