在Asp.net MVC4中按频道名称检索youtube视频时出错

时间:2015-10-04 06:27:58

标签: asp.net-mvc-4 youtube-api youtube-data-api

我正在尝试通过Asp.net mvc4网络应用程序中的频道名称检索youtube视频。我尝试使用Google搜索并使用我找到的所有代码进行测试但最终结果显示" 执行请求失败:{{ 3}} " 任何帮助都会受到赞赏,我仍然试图谷歌寻求解决方案。 感谢

模型

public class Youtube
    {
        public string YouTubeMovieID { get; set; }
        public string YouTubeMovieTitle { get; set; }
    }

    public class YouTubeHelper
    {
        const string YT_CHANNEL_NAME = "Heaven Luk";
        const string YT_DEVELOPER_ID = "Devloper ID here";

        public static List<Youtube> GetVideos()
        {
            YouTubeRequestSettings ytSettings = new YouTubeRequestSettings("MyTestingWebsite", YT_DEVELOPER_ID);
            YouTubeRequest ytRequest = new YouTubeRequest(ytSettings);
            string feedURL = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published", YT_CHANNEL_NAME);
            Feed<Video> videoFeed = ytRequest.Get<Video>(new Uri(feedURL));

            return (from video in videoFeed.Entries
                    select new Youtube() { YouTubeMovieID = video.VideoId, YouTubeMovieTitle = video.Title }).ToList();
        }

查看

@model IEnumerable<MyTestingProject.Models.YouTubeHelper>
@{

    Layout = "~/Views/Shared/_Foundation.cshtml";
}

@foreach (var v in Model)
{
<object width="427" height="258">
           <param name="movie" value="http://www.youtube.com/v/@v.YouTubeMovieID" />
           <param name="allowFullScreen" value="true" />
           <param name="allowscriptaccess" value="always"/>
           <param name="wmode" value="opaque" />
           <embed src="http://www.youtube.com/v/@v.YouTubeMovieID"
              type="application/x-shockwave-flash" width="427"
              height="258" allowscriptaccess="always" allowfullscreen="true"
              wmode="opaque"></embed>  </object>

}

控制器

 public ActionResult Videos()
        {
            var videos = YouTubeHelper.GetVideos();
            return View(videos);
        }

1 个答案:

答案 0 :(得分:0)

V2 YouTube API已被弃用。你应该使用V3代替。如果您想要获得频道的上传视频,则必须提供频道名称或ID,获取上传播放列表,然后从该播放列表中获取视频。请参阅代码示例here。或者,您可以search为指定频道的视频指定频道ID并设置Foo