对 YouTube oembed 调用的 JSONp 请求的响应给出“无效标签”错误
我正在使用 oembed 对 youtube 进行 JSONp 调用,响应时 firebug 给出“无效标签”错误
这是我的代码
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 请求类似的问题吗?
I am making a JSONp call to youtube using oembed and on response firebug gives "invalid label" error
Here is my code
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);
});
Anyone ran into similar problem with oembed jsonp requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题
YouTube API 不支持 JSONP - 请参阅:
解决方案
不需要服务器端代理,也不需要 API 密钥。
而不是:
尝试使用 Noembed 服务:
作为奖励,当您更改
url
至:以及许多其他支持的网站。
演示
请参阅 JS Fiddle 上的 DEMO。
另请参阅
另请参阅这些问题:
Problem
YouTube API doesn't support JSONP - see:
Solution
There is no need for a server-side proxy and no API keys are required.
Instead of:
Try this, using the Noembed service:
As a bonus this will also work with Vimeo links when you change
url
to:and many other supported sites.
Demo
See DEMO on JS Fiddle.
See also
See also those questions:
Youtube 的 Oembed API 目前未将 JSON 响应包装在回调中。 ATM 根本不支持 JSONP,而且这似乎不会很快改变:
https://groups.google.com/forum/ ?fromgroups=#!topic/youtube-api-gdata/5KuXxlLK07g
以下是相关功能请求的票证:https://code.google.com/p/gdata-issues/issues/detail?id=4329
最简单的解决方案是实现一个小型服务器端代理代表客户端发出请求。
Youtube’s Oembed API doesn’t currently wrap the JSON response in a callback. JSONP is simply not supported atm., and it seems like this won’t change anytime soon:
https://groups.google.com/forum/?fromgroups=#!topic/youtube-api-gdata/5KuXxlLK07g
Here’s a ticket for a related feature request: https://code.google.com/p/gdata-issues/issues/detail?id=4329
The easiest solution would be to implement a small server side proxy to make the requests on the client’s behalf.