0

YouTube 有一项功能,您可以在自己的频道上放一段视频,供未订阅用户在访问您的频道时观看。我正在尝试找到一种使用 JSON(ASP.NET MVC4)在网页上显示此视频的方法,但我对所有标签等并不熟悉。我在谷歌上查找了一些信息,在这里:https ://developers.google.com/youtube/v3/docs/channels并找到了这个:brandingSettings.channel.unsubscribedTrailer但我不太确定如何访问它。

这是我的代码: $(document).ready(function () {

    var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/XXXXXXXXXXXX?v=2&alt=json&max-results=50&callback=?';
    var videoURL = 'http://www.youtube.com/watch?v=';
    $.getJSON(playListURL, function (data) {
        var list_data = "";
        var column_count = -1;
        var end_li = "</li>";
        var begin_div = "<div class='inner-item'>";
        var end_div = "</div>";
        var html_data = "";
        var tags = new Array();

        $.each(data.feed.entry, function (i, item) {
            column_count = column_count + 1;
            var feedTitle = item.title.$t;
            var feedURL = item.link[1].href;
            var videoDate = new Date(item.published.$t).toLocaleDateString()
            var fragments = feedURL.split("/");
            var videoID = fragments[fragments.length - 2];
            var description = item.media$group.media$description.$t;
            var url = videoURL + videoID;
            var thumb = "http://img.youtube.com/vi/" + videoID + "/default.jpg";

            //Do some stuff with the vid.
            });
        });

我是否需要为此访问不同的 URL,或者我可以在item某处找到该物业的信息吗?

上面的代码用于显示来自特定播放列表的所有视频,它运行良好(使用所有代码)但我只需要找到unsubscribeTrailer并显示它,如果可能的话。

4

1 回答 1

2

You do have the wrong URL ... the documentation you reference that talks about the 'unsubscribedTrailer' field is for v3 of the API, but your code is doing a call to v2, where the field hasn't been exposed. Instead, you could try this URL:

https://www.googleapis.com/youtube/v3/channels?part=snippet,brandingSettings&id={DESIRED_CHANNEL_ID}&key={YOUR_API_KEY}

The important factor is to include 'brandingSettings' in your 'part' parameter, so that the fields you want are returned with the JSON response.

于 2013-06-14T05:39:01.343 回答