我正在尝试通过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);
}