2013-06-23 126 views
2

我試圖在C#中顯示來自我的YouTube頻道的視頻列表,但我不能。顯示來自我的YouTube頻道的視頻列表

當我運行程序時,我得到這樣一個錯誤:

Object reference not set to an instance of an object.


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); 

     } 

任何幫助將不勝感激。

回答

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); 
} 
+0

我輸入錯了,我糾正它 –

+0

它是不是問題 –

+0

什麼行是拋出錯誤? – keyboardP