使用oembed嵌入youtube视频

编程入门 行业动态 更新时间:2024-10-14 20:20:23
本文介绍了使用oembed嵌入youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用oembed从youtube链接获取jQuery的嵌入代码:

I want to use oembed to get the embed code from youtube links with jQuery:

var url = "www.youtube/watch?v=iwGFalTRHDA"; url = encodeURIComponent(url); $.getJSON('youtube/oembed?url='+url+'&format=json', function(data) { console.log(data); });

我没有得到任何数据。

有趣的是,如果我浏览到网址,我会得到正确的回复:

Funny thing is, that if I browse to the url I get the right response:

www.youtube/oembed?url=http%3A%2F%2Fwww.youtube%2Fwatch%3Fv%3DiwGFalTRHDA&format=json`

引导我

{ provider_url: "www.youtube/" title: "Trololo" html: "<object width="425" height="344"><param name="movie" value="www.youtube/v/iwGFalTRHDA?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="www.youtube/v/iwGFalTRHDA?version=3" type="application/x-shockwave-flash" width="425" height="344" allowscriptaccess="always" allowfullscreen="true"></embed></object>" author_name: "KamoKatt" height: 344 thumbnail_width: 480 width: 425 version: "1.0" author_url: "www.youtube/user/KamoKatt" provider_name: "YouTube" thumbnail_url: "i2.ytimg/vi/iwGFalTRHDA/hqdefault.jpg" type: "video" thumbnail_height: 360 }

我还使用了jquery oembed插件,但是如果请求成功,也会抛出onError选项。

I also used the jquery oembed plugin, but the onError option is always thrown, also if the request was successful.

我真的很期待一些想法...

I'm really looking forward for some ideas...

推荐答案

实际上问题是你违反了浏览器相同的源策略和跨域ajax请求。有一些潜在的工作方法 - 遗憾的是最好的 JSONP未实施通过YouTube 。接下来最好的是使用Flash进行传输。这由 YUI-IO实用程序使用。您也可以在这里看到 Jquery建议。

Actually the problem is you're violating the browser same origin policy with a cross domain ajax request. There a few work potential work arounds -- unfortunately the best JSONP, isn't implemented by YouTube. The next best is using Flash for transport. This is used by YUI-IO utility. Also you can see Jquery suggestions here.

更多推荐

使用oembed嵌入youtube视频

本文发布于:2023-11-05 18:41:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   oembed   youtube

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!