我正在使用oembed对youtube进行JSONp调用,并且响应firebug会出现“invalid label”错误
site = "www.youtube.com"; url = "http://www.youtube.com/watch?v=slORb622ZI8"; $.getJSON("http://"+site+"/oembed?callback=?",{"format":"json","url":url},function(data){ alert("hello:\n"+data); alert(data.provider_url); });
任何人遇到oembed jsonp请求的类似问题?@H_404_3@
解决方法
问题
YouTube API不支持JSONP – 请参阅:@H_404_3@
> Issue 4329: oEmbed callback for JSONP.@H_404_3@
解@H_404_3@
不需要服务器端代理,也不需要API密钥.@H_404_3@
代替:@H_404_3@
var url = "http://www.youtube.com/watch?v=slORb622ZI8"; $.getJSON("http://www.youtube.com/oembed?callback=?",{"format": "json","url": url},function (data) { alert("hello:\n"+data); alert(data.provider_url); });
var url = "http://www.youtube.com/watch?v=slORb622ZI8"; $.getJSON("https://noembed.com/embed?callback=?",function (data) { alert("hello:\n" + data); alert(data.provider_url); });
作为奖励,当您将网址更改为以下内容时,这也适用于Vimeo链接:@H_404_3@
var url = "https://vimeo.com/45196609";
和许多其他supported sites.@H_404_3@
演示@H_404_3@
也可以看看@H_404_3@
另见这些问题:@H_404_3@
> Youtube Video title with API v3 without API key?
> Get Youtube information via JSON for single video (not feed) in Javascript@H_404_3@