我正试图在C#中显示我的YouTube频道的视频列表,但我不能。
当我运行程序时,出现了这样的错误:
对象引用未设置为对象的实例。
YouTubeRequestSettings settings = new YouTubeRequestSettings("my app name",
"my devkey",
"my email", "my password");
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads";
Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
foreach (Video entry in videofeed.Entries)
{
list.Items.Add(entry);
}
任何帮助将不胜感激。
答案 0 :(得分:3)
看起来应该是
YouTubeRequest settings = new YouTubeRequest(ayarlar);
否则你试图将尚未实例化的settings
变量作为参数传递给YouTubeRequest
构造函数。
从评论中更新
由于您需要全局变量,请不要在此处创建新实例并使用现有的
//earlier code
string feedUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads";
//the Feed<Video> has been removed because you want to use the global variable
videoFeed = request.Get<Video>(new Uri(feedUrl));
foreach (Video entry in videofeed.Entries)
{
list.Items.Add(entry);
}