0
我試圖通過頻道名稱在Asp.net mvc4 web應用程序中檢索youtube視頻。我嘗試了使用Google搜索的所有代碼進行搜索並進行了測試,但最終結果爲「執行請求失敗:http://gdata.youtube.com/feeds/api/users/channelname/uploads?orderby=published「 。任何幫助將被讚賞,我仍然試圖谷歌它的解決方案。 感謝在Asp.net MVC4中通過頻道名稱檢索youtube視頻時出錯
型號
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);
}