对 YouTube oembed 调用的 JSONp 请求的响应给出“无效标签”错误

发布于 2024-09-16 00:41:10 字数 374 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-09-23 00:41:10

问题

YouTube API 不支持 JSONP - 请参阅:

解决方案

不需要服务器端代理,也不需要 API 密钥。

而不是:

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);
});

尝试使用 Noembed 服务:

var url = "http://www.youtube.com/watch?v=slORb622ZI8";

$.getJSON("https://noembed.com/embed?callback=?",
    {"format": "json", "url": url}, function (data) {
    alert("hello:\n" + data);
    alert(data.provider_url);
});

作为奖励,当您更改 url 至:

var url = "https://vimeo.com/45196609";

以及许多其他支持的网站

演示

请参阅 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:

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);
});

Try this, using the Noembed service:

var url = "http://www.youtube.com/watch?v=slORb622ZI8";

$.getJSON("https://noembed.com/embed?callback=?",
    {"format": "json", "url": url}, function (data) {
    alert("hello:\n" + data);
    alert(data.provider_url);
});

As a bonus this will also work with Vimeo links when you change url to:

var url = "https://vimeo.com/45196609";

and many other supported sites.

Demo

See DEMO on JS Fiddle.

See also

See also those questions:

写下不归期 2024-09-23 00:41:10

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文