oembedを使用して、jQueryを使用してYouTubeリンクから埋め込みコードを取得したいと思います。
var url = "http://www.youtube.com/watch?v=iwGFalTRHDA";
url = encodeURIComponent(url);
$.getJSON('http://youtube.com/oembed?url='+url+'&format=json', function(data) {
console.log(data);
});
さて、私はデータを取得しません。
面白いことに、URLを参照すると、正しい応答が得られます。
http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiwGFalTRHDA&format=json`
私をに導きます
{
provider_url: "http://www.youtube.com/"
title: "Trololo"
html: "<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/iwGFalTRHDA?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/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: "http://www.youtube.com/user/KamoKatt"
provider_name: "YouTube"
thumbnail_url: "http://i2.ytimg.com/vi/iwGFalTRHDA/hqdefault.jpg"
type: "video"
thumbnail_height: 360
}
jquery oembedプラグインも使用しましたが、リクエストが成功した場合も、onErrorオプションが常にスローされます。
私は本当にいくつかのアイデアを楽しみにしています...