Get Youtube information via JSON for single video (not feed) in Javascript

UPDATED 2018

API v2 deprecated. New youtube api v3 works only with developer token and has limitation for free connections.

You can get JSON without API:

http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=ojCkgU5XGdg&format=json

Or xml

http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=ojCkgU5XGdg&format=xml



new 2018 json response has

{
  "html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/ojCkgU5XGdg?feature=oembed\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>",
  "title": "Creativity and Drugs (Eng Sub)",
  "thumbnail_height": 360,
  "provider_name": "YouTube",
  "author_url": "https://www.youtube.com/user/serebniti",
  "thumbnail_width": 480,
  "height": 270,
  "provider_url": "https://www.youtube.com/",
  "type": "video",
  "width": 480,
  "version": "1.0",
  "author_name": "serebniti",
  "thumbnail_url": "https://i.ytimg.com/vi/ojCkgU5XGdg/hqdefault.jpg"
}

Thumbs:

hqdefault.jpg has less quality but always exist.

http://img.youtube.com/vi/ojCkgU5XGdg/hqdefault.jpg

http://img.youtube.com/vi/ojCkgU5XGdg/sddefault.jpg

Max size

https://i.ytimg.com/vi/ojCkgU5XGdg/maxresdefault.jpg

Mini thumbs:

http://img.youtube.com/vi/ojCkgU5XGdg/0.jpg
http://img.youtube.com/vi/ojCkgU5XGdg/1.jpg
http://img.youtube.com/vi/ojCkgU5XGdg/2.jpg
http://img.youtube.com/vi/ojCkgU5XGdg/3.jpg

Annotations

http://www.youtube.com/annotations_invideo?cap_hist=1&video_id=ojCkgU5XGdg

parse mobile page 16kb

https://m.youtube.com/watch?v=ojCkgU5XGdg

don't forget change user agent to iOS / Safari 7

also

http://www.youtube.com/get_video_info?html5=1&video_id=ojCkgU5XGdg

also how embed youtube live

https://www.youtube.com/embed/live_stream?channel=UCkA21M22vGK9GtAvq3DvSlA

Where UCkA21M22vGK9GtAvq3DvSlA is your channel id. You can find it inside youtube account on "My Channel" link.

Live thumb

https://i.ytimg.com/vi/W-fSCPrYSL8/hqdefault_live.jpg

UPDATE MAY/2015:

This solution doesn't work properly, YouTube API v2 is in process to be discontinued soon.

More info at: https://www.youtube.com/devicesupport


Try something like this:

var video_id='VA770wpLX-Q';

$.getJSON('http://gdata.youtube.com/feeds/api/videos/'+video_id+'?v=2&alt=jsonc',function(data,status,xhr){
    alert(data.data.title);
    // data contains the JSON-Object below
});

Demo: http://jsfiddle.net/wqwxg/

The returned JSON looks like this:

{
    "apiVersion": "2.1",
    "data": {
        "id": "VA770wpLX-Q",
        "uploaded": "2011-02-24T22:31:02.000Z",
        "updated": "2012-04-08T21:37:06.000Z",
        "uploader": "drdrevevo",
        "category": "Music",
        "title": "Dr. Dre - I Need A Doctor (Explicit) ft. Eminem, Skylar Grey",
        "description": "Music video by Dr. Dre performing I Need A Doctor featuring Eminem and Skylar Grey (Explicit). © 2011 Aftermath Records",
        "tags": ["Dr", "Dre", "Eminem", "New", "Song", "Skylar", "Grey", "GRAMMYs", "Dr.", "Need", "Doctor", "video", "Eazy", "N.W.A.", "NWA", "easy", "drdre", "and", "em"],
        "thumbnail": {
            "sqDefault": "http://i.ytimg.com/vi/VA770wpLX-Q/default.jpg",
            "hqDefault": "http://i.ytimg.com/vi/VA770wpLX-Q/hqdefault.jpg"
        },
        "player": {
            "default": "http://www.youtube.com/watch?v=VA770wpLX-Q&feature=youtube_gdata_player"
        },
        "content": {
            "5": "http://www.youtube.com/v/VA770wpLX-Q?version=3&f=videos&app=youtube_gdata"
        },
        "duration": 457,
        "aspectRatio": "widescreen",
        "rating": 4.902695,
        "likeCount": "430519",
        "ratingCount": 441253,
        "viewCount": 88270796,
        "favoriteCount": 306556,
        "commentCount": 270597,
        "status": {
            "value": "restricted",
            "reason": "requesterRegion"
        },
        "restrictions": [{
            "type": "country",
            "relationship": "deny",
            "countries": "DE"
        }],
        "accessControl": {
            "comment": "allowed",
            "commentVote": "allowed",
            "videoRespond": "allowed",
            "rate": "allowed",
            "embed": "allowed",
            "list": "allowed",
            "autoPlay": "denied",
            "syndicate": "allowed"
        }
    }
}

Problem

YouTube API doesn't support JSONP as it should - see Issue 4329: oEmbed callback for JSONP. Also, YouTube Data API v2 is deprecated.

Solution

You can use the Noembed service to get oEmbed data with JSONP for YouTube videos.

Bonus

  • no API keys are needed
  • no server-side proxy is required

Example

For your VA770wpLX-Q video, you can try a link like this:

https://noembed.com/embed?url=http://www.youtube.com/watch?v=VA770wpLX-Q

Or this for JSONP:

https://noembed.com/embed?callback=example&url=http://www.youtube.com/watch?v=VA770wpLX-Q

Those links have a standard URL of a YouTube video passed as the url parameter. It works not only with YouTube but also with Vimeo and other sites with URLs like:

https://noembed.com/embed?url=https://vimeo.com/45196609

Demo

Here is a simple example using jQuery:

var id = 'VA770wpLX-Q';
var url = 'https://www.youtube.com/watch?v=' + id;

$.getJSON('https://noembed.com/embed',
    {format: 'json', url: url}, function (data) {
    alert(data.title);
});

See: DEMO on JS Bin.

Other options

  • Embedly (commercial service, free up to 5000 URLs/month)
  • Oohembed (update: now bought by Embedly, but the source is available)
  • AutoEmbed (update: seems to be down or discontinued)

More info

See also those questions:

  • Youtube Video title with API v3 without API key?
  • Response for JSONp request to youtube oembed call giving "invalid label" error