Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- public bool YouTubeImport(string VideoID)
- {
- try
- {
- WebClient myDownloader = new WebClient();
- myDownloader.Encoding = System.Text.Encoding.UTF8;
- string jsonResponse = myDownloader.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + VideoID + "&key=" + ytKey + "&part=snippet");
- JavaScriptSerializer jss = new JavaScriptSerializer();
- var dynamicObject = Json.Decode(jsonResponse);
- var item = dynamicObject.items[0].snippet;
- Title = item.title;
- jsonResponse = myDownloader.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + VideoID + "&key=" + ytKey + "&part=contentDetails");
- dynamicObject = Json.Decode(jsonResponse);
- string tmp = dynamicObject.items[0].contentDetails.duration;
- Duration = Convert.ToInt32(System.Xml.XmlConvert.ToTimeSpan(tmp).TotalSeconds);
- Url = "http://www.youtube.com/watch?v=" + VideoID;
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement