Youtube Video title with API v3 without API key?

前端 未结 4 1254
猫巷女王i
猫巷女王i 2020-12-03 03:03

Is it possible to get the video title using the video ID with API v3 without the API key? I could not find any information or example of getting the title i

4条回答
  •  情深已故
    2020-12-03 03:45

    No need for API key

    To get the video title, you will NOT need an API key, and you'll need to make a request to:

    https://noembed.com/embed?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ

    Change the YouTube URL for the video that you need.

    It also works with Vimeo and many other supported sites with URLs like:

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

    Details

    It is not possible to get the video title using the video ID with API v3 without the API key if you use the API directly. The YouTube Data API v2 is deprecated (see: YouTube Data API v2 Deprecation: Frequently Asked Questions) and currently the YouTube API doesn't support oEmbed with JSONP as it should (see Issue 4329: oEmbed callback for JSONP).

    But fortunately there is the Noembed service that lets you get the titles (and other data) of YouTube videos with JSONP and without the API key.

    Demo

    Here is a simple demo to get the title with jQuery:

    var id = 'dQw4w9WgXcQ';
    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.

    See also these questions:

    • Get Youtube information via JSON for single video (not feed) in Javascript
    • Response for JSONp request to youtube oembed call giving "invalid label" error

提交回复
热议问题