Typically
Typically

Reputation: 69

Youtube Data API v3 with C#

Here's my question:

So when you go to https://www.googleapis.com/youtube/v3/playlists?id=PLEylltUN0Ao6PvGUOJuVOAh6sSQvwoZQ3&key=AIzaSyBr7_g-xlBCBR6Mxk_2P0GRWeM5b_aJ5uM&part=snippet

You get a lot of information but I only want one thing and that is:

at thumbnails then default and then url so how do I do that?

To make it more clear:

"thumbnails": {
 "default": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg",
  "width": 120,
  "height": 90
 },
 "medium": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/mqdefault.jpg",
  "width": 320,
  "height": 180
 },
 "high": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/hqdefault.jpg",
  "width": 480,
  "height": 360
 },
 "standard": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/sddefault.jpg",
  "width": 640,
  "height": 480
 },
 "maxres": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/maxresdefault.jpg",
  "width": 1280,
  "height": 720
 }
},

And then

     "default": {
  "url": "https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg",
  "width": 120,
  "height": 90
 },

And then

"url": "https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg",

I want to return that url: https://i.ytimg.com/vi/iilXL9y2HtE/default.jpg

I'm coding in C#

Upvotes: 0

Views: 818

Answers (1)

Thomas
Thomas

Reputation: 126

I had a look on StackOverflow for an answer to your question and found these related questions, which may be helpful for you.

Deserializing JSON using JSon.NET with dynamic data

How to get a json string from url?

The first link describes how to achieve this using either SimpleJSON or Json.NET (http://www.newtonsoft.com/json). The second link describes how to download the JSON you want to parse in C#.

In your case, you would have to change

string title = json.query.pages["6695"].title;

to something like

string url = json["items"][0]["snippet"]["thumbnails"]["default"]["url"];

in order to get the required url (You don't need to bother with the foreach statement). Also, "text" in the line

dynamic json = SimpleJson.DeserializeObject(text)

would have to be replaced with the downloaded JSON (see the second link).

Upvotes: 1

Related Questions