0

I'm using an ajax call in order to retrieve data from the youtube api.I managed to receive the jason,however I'm not really sure how could I extract the field i need.

I will attach an image with what I'm getting.

Console print with the actual result

enter image description here

I tried to convert this json to an object,also I tried to retrieve it as I would with a normal vector element(using the layers as indexes),but nothing seems to work.

Also,is there any way to retrieve from the youtube API just the "textDisplay" field?(So I could pass it to a Highchart(Javascript library for charts) and draw the chart directly?)

My call looks like this:

$.ajax({
  dataType: "json",
  type: 'GET',
  url: "https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&maxResults=5&videoId=lyZQPjUT5B4&fields=items%2Fsnippet%2FtopLevelComment%2Fsnippet%2FtextOriginal&key=[thereisMyKey]"
}

*Using this call will probably fail,since I have not provided you the key

Nemus
  • 3,879
  • 12
  • 38
  • 57
Ban Istvan
  • 101
  • 8
  • do you want to iterate over the responses or simply want to access the first element of items array? – Anand Siddharth Nov 26 '17 at 20:18
  • No need to convert it....it is already converted in the ajax success handler – charlietfl Nov 26 '17 at 20:21
  • I found the correct way: console.log(result.items[0].snippet.topLevelComment.snippet.textOriginal); My mistake was that instead of result.items[0] I always tried directly with result.snippet.After i got an "undefined in console i knew what to look for on this forum.Anyway,my question is still actual,since I did not found a way to retrieve just the 'originalText' via the youtube API call. – Ban Istvan Nov 26 '17 at 20:40
  • @charlietfl the mark is somewhat legit,since half of my answer was found on the topic indicated by you,also after your comment I found another topic where someone said that "using json, jquery will make parse for you",i didn't know that.Thanks for your help,even if it came as a "mark".Do you know the answer for the second question too? (Can I get a response that contains only the 'originalText' field instead of getting the structure shown in the image above?) – Ban Istvan Nov 26 '17 at 20:48
  • You get the response then have to iterate through that response to access whtever it is you need – charlietfl Nov 26 '17 at 20:50

0 Answers0