透过oEmbed YouTube的 [英] Oembed for youtube

查看:173
本文介绍了透过oEmbed YouTube的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否需要开发者对我的网站使用透过oEmbed YouTube的钥匙吗?

存在的问题是,继code不工作,它不返回更迭

  $阿贾克斯({
                    网址:http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=PVzljDmoPVs
                    数据类型:JSONP
                    超时:15000,
                    成功:函数(JO){
                        如果(JO){
                            setIMg(jo.thumbnail_url);
                            的setTitle(jo.title);
                        }
                    }
                });

但是,当我在那么火浏览器的URL它给我的JSON:


  

{PROVIDER_URL:HTTP:\\ / \\ / www.youtube.com \\ /,thumbnail_url:HTTP:\\ / \\ / i1.ytimg.com \\ / VI \\ /PVzljDmoPVs\\/hqdefault.jpg,称号:大卫·库塔 - 她沃尔夫(分崩离析)英尺SIA,HTML:\\ u003ciframe宽度= \\480 \\HEIGHT = \\270 \\ SRC = \\HTTP:\\ / \\ / www.youtube.com \\ /嵌入\\ / PVzljDmoPVs FS = 1 \\ u0026feature =透过oEmbed \\FRAMEBORDER = \\0 \\的allowFullScreen \\ u003e \\ u003c \\ / IFRAME \\ u003e AUTHOR_NAME:davidguettavevo,高度:270,thumbnail_width:480,宽度:480,版本:1.0,author_url:HTTP:\\ / \\ / www.youtube.com \\ / USER \\ / davidguettavevo,PROVIDER_NAME:YouTube的型:视频,thumbnail_height:360}



解决方案

首先不,你并不需要一个开发人员密钥才能使用YouTube的透过oEmbed端点。

其次,YouTube不支持JSONP其透过oEmbed终点,那是你调用失败的原因。为了解决这个问题,你可以使用一个第三方透过oEmbed提供商,如 reEmbed.me

下面是示例code:

  VAR的serviceUrl =htt​​p://reembed.me/api/v1/OEmbed?url=;
VAR URL =htt​​p://www.youtube.com/watch?v=PVzljDmoPVs;
$ .getJSON(+的serviceUrl EN codeURIComponent(URL)+&放大器;回调=,空,函数(JO){
    如果(JO){
        setIMg(jo.thumbnail_url);
        的setTitle(jo.title);
    }
});

注意,传递的链接是实际的视频网址,而不是透过oEmbed端点连接。

Do I need Developer's key for using oembed for youtube in my website?

The problems is that following code does not works, It does not returns to succes

 $.ajax({
                    url: "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=PVzljDmoPVs",
                    dataType: "jsonp",
                    timeout: 15000,
                    success: function (jo) {
                        if (jo) {
                            setIMg(jo.thumbnail_url);
                            setTitle(jo.title);
                        }
                    }
                });

But when i fire the url in the browser then it gives me the json:

{"provider_url": "http:\/\/www.youtube.com\/", "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/PVzljDmoPVs\/hqdefault.jpg", "title": "David Guetta - She Wolf (Falling To Pieces) ft. Sia", "html": "\u003ciframe width=\"480\" height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/PVzljDmoPVs?fs=1\u0026feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "author_name": "davidguettavevo", "height": 270, "thumbnail_width": 480, "width": 480, "version": "1.0", "author_url": "http:\/\/www.youtube.com\/user\/davidguettavevo", "provider_name": "YouTube", "type": "video", "thumbnail_height": 360}

解决方案

Firstly no, you don't need a developer key to use the oembed endpoints of YouTube.

Secondly, YouTube doesn't support JSONP on its oEmbed endpoint, that's the reason your call fails. In order to fix it, you can use a third party oEmbed provider such as reEmbed.me

Here is the sample code:

var serviceUrl = "http://reembed.me/api/v1/OEmbed?url=";
var url = "http://www.youtube.com/watch?v=PVzljDmoPVs";
$.getJSON(serviceUrl + encodeURIComponent(url) + "&callback=?", null, function (jo) {
    if (jo) {
        setIMg(jo.thumbnail_url);
        setTitle(jo.title);
    }
});

Note that the link being passed is the actual video url, not the oembed endpoint link.

这篇关于透过oEmbed YouTube的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆