Advertisement
IzaacJ

Requesting multiple Youtube playlist ids in a foreach

Feb 1st, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. // GlobalVariables.YoutubePlaylistId is defined like this:
  2. //                        public static string[] YoutubePlaylistId = {"---A-PLAYLIST-ID---", "---ANOTHER-PLAYLIST-ID---"};
  3.  
  4. #region "Load Youtube Data"
  5.             int i = 0;
  6.             foreach (string playlistID in GlobalVariables.YoutubePlaylistId)
  7.             {
  8.                 RestRequest YoutubeRequest = new RestRequest("/playlistItems?part=snippet&playlistId=" + playlistID + "&key=" + GlobalVariables.YoutubeClientID + "&maxResults=25", Method.GET);
  9.                 YoutubeRequest.RequestFormat = DataFormat.Json;
  10.                 GlobalVariables.YoutubeClient.ExecuteAsync<PlaylistObject>(YoutubeRequest, (YoutubeResponse) =>
  11.                 {
  12.                     PlaylistObject pl = YoutubeResponse.Data;
  13.                     NextPageToken[i] = pl.nextPageToken;
  14.                     foreach (Item v in pl.items)
  15.                     {
  16.                         if (v.snippet.title != "Private video")
  17.                         {
  18.                             AddVideo(v.snippet, i);
  19.                         }
  20.                     }
  21.                     i++;
  22.                 });
  23.             }
  24.  
  25. // This gives me a Object reference not set to an instance of an object. Have tried to find which object/line of code. Using RestSharp and RestSharpEx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement