对于JSONp请求的响应,该响应是对YouTube嵌入呼叫的响应,其中给出了“无效标签"错误 [英] Response for JSONp request to youtube oembed call giving "invalid label" error

查看:1624
本文介绍了对于JSONp请求的响应,该响应是对YouTube嵌入呼叫的响应,其中给出了“无效标签"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用oembed对youtube进行JSONp调用,并且响应时萤火虫给出了无效标签"错误

I am making a JSONp call to youtube using oembed and on response firebug gives "invalid label" error

这是我的代码

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

有人在jsonp请求受约束时遇到了类似的问题吗?

Anyone ran into similar problem with oembed jsonp requests?

推荐答案

问题

YouTube API不支持JSONP-请参阅:

Problem

YouTube API doesn't support JSONP - see:

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

There is no need for a server-side proxy and no API keys are required.

代替:

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更改为:

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

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

和许多其他受支持的站点.

请参见JS小提琴上的 DEMO

See DEMO on JS Fiddle.

另请参阅那些问题:

  • Youtube Video title with API v3 without API key?
  • Get Youtube information via JSON for single video (not feed) in Javascript

这篇关于对于JSONp请求的响应,该响应是对YouTube嵌入呼叫的响应,其中给出了“无效标签"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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