【问题标题】:Embedding YouTube Live Feed嵌入 YouTube 实时供稿
【发布时间】:2012-09-21 00:15:53
【问题描述】:

我正在尝试使用 YouTube API v2.0 - Retrieving Live Events 提取最新的 YouTube 直播活动供稿 但我的脚本似乎不起作用。这是我的代码。

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    </head>
    <body>

     <div id="static_video"></div>

      <script> 
          $(document).ready(function() {
          $(function () {   
              $.getJSON( "https://gdata.youtube.com/feeds/api/users/ElektraRecords/live/events?v=2&inline=true&alt=json-in-script&status=pending&orderby=published$callback=?",
            function (data) {   
                $.each(data.feed.content.entry, function(i,entry) { 
                    var videoid = 'http://www.youtube.com/embed/' + entry.yt$videoid.$t;
                    var title = '<h1>' + entry.media$title.$t + '</h1>';
                var video = +title+ "<iframe width='420' height='315' src='"+videoid+ "' frameborder='0' allowfullscreen></iframe>";
                $('#static_video').html(video);
                    });
                });
            });
        });
      </script>

    </body>
</html>

【问题讨论】:

标签: javascript jquery youtube-api youtube-livestreaming-api


【解决方案1】:

您缺少一个依赖脚本。显然,您需要在文档的标题中包含 API 的 gdata 部分。查看我放在 JSFiddle 上的浏览​​器调试器和脚本:http://jsfiddle.net/2NDrC/ - 您可能希望嵌入的 API 在这里:https://code.google.com/p/google-api-javascript-client/

如果您查看使用 javascript 检索的 URL 的作用,您会发现它是对 gdata api 中方法的方法调用:

网址:https://gdata.youtube.com/feeds/api/users/ElektraRecords/live/events?v=2&amp;inline=true&amp;alt=json-in-script&amp;status=pending&amp;orderby=published$callback=?

返回

gdata.io.handleScriptLoaded({"version":"1.0","encoding":"UTF-8","feed":{"xmlns$app":"http://www.w3...

并作为javascript执行。因此,必须提供一个名为 gdata.io.handleScriptLoaded 的方法才能成功执行。

此处显示了解释如何伪造 gdata.io.handledScriptLoaded 方法以仅提取数据的解决方法:https://groups.google.com/forum/?fromgroups=#!topic/jquery-en/83Kpr9oSxFM

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 2010-12-03
    • 2011-10-28
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多