本文介绍了透过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:

解决方案

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的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:32