Guest User

Youtube info code not working?

a guest
Jul 21st, 2016
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. This is the code i have. It gets the video id when someone type a certain command with the video id it uses the function but when it gets to Json.Decode(JsonResponse) it returns false instead of true with the values like the title, duration, description.
  2.  
  3.  
  4. public bool YouTubeImport(string VideoID)
  5.         {
  6.             try
  7.             {
  8.                 WebClient myDownloader = new WebClient();
  9.                 myDownloader.Encoding = System.Text.Encoding.UTF8;
  10.  
  11.                 string jsonResponse = myDownloader.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + VideoID + "&key=" + ytKey + "&part=snippet");
  12.                 JavaScriptSerializer jss = new JavaScriptSerializer();
  13.                 var dynamicObject = Json.Decode(jsonResponse);
  14.                 var item = dynamicObject.items[0].snippet;
  15.  
  16.                 Title = item.title;
  17.  
  18.                 jsonResponse = myDownloader.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + VideoID + "&key=" + ytKey + "&part=contentDetails");
  19.                 dynamicObject = Json.Decode(jsonResponse);
  20.                 string tmp = dynamicObject.items[0].contentDetails.duration;
  21.                 Duration = Convert.ToInt32(System.Xml.XmlConvert.ToTimeSpan(tmp).TotalSeconds);
  22.  
  23.                 Url = "http://www.youtube.com/watch?v=" + VideoID;
  24.  
  25.                 return true;
  26.             }
  27.             catch (Exception ex)
  28.             {
  29.                 return false;
  30.             }
  31.         }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×