SReject / JSON-For-Mirc

JSON parser for mIRC
19 stars 6 forks source link

JSONOpen returns different result on youtube api call #50

Closed preginald closed 4 years ago

preginald commented 4 years ago

I wish to get the title value with the following alias but I'm getting random values even with the fuzzy option.

Example 1

alias youtube {
  JSONOpen -u youtube https://www.googleapis.com/youtube/v3/videos?id=xAPqoS_FCTs&key=<APIKEY_HIDDEN>&part=snippet
  echo -a $json(youtube,etag)
}

It echos the different result for the etag key image

Example 2 Alternatively when I pick the title key with as seen below I get random results as per the screenshot above.

alias youtube {
  JSONOpen -u youtube https://www.googleapis.com/youtube/v3/videos?id=xAPqoS_FCTs&key=<APIKEY_HIDDEN>&part=snippet
  echo -a $json(youtube,items,0,snippet,title).fuzzy
}

Any ideas to fix?

This is the data that comes back when I run in browser

{
 "kind": "youtube#videoListResponse",
 "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/92YIo5nK5JEVr5AB3xfw4Vc-G6s\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/qJkJVVYcTxKzBzzhxeDtZp3xZcA\"",
   "id": "xAPqoS_FCTs",
   "snippet": {
    "publishedAt": "2019-11-07T17:00:09.000Z",
    "channelId": "UCq-ylUNa9RoTK5jr6TBOYag",
    "title": "Learning To Become A Racing Driver",
    "description": "3 days of driving with the end goal of passing the racing driver exam. Do I have what it takes?\n\nIf you enjoy the video then please hit that like button!\n\nHelp support the ",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/xAPqoS_FCTs/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/xAPqoS_FCTs/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/xAPqoS_FCTs/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/xAPqoS_FCTs/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/xAPqoS_FCTs/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Jimmy Broadbent",
    "tags": [
     "Formula 1",
     "Senna",
     "Hamilton",
     "Prost",
     "F1 2019",
     "ESPORTS",
     "Gran Turismo Sport"
    ],
    "categoryId": "20",
    "liveBroadcastContent": "none",
    "localized": {
     "title": "Learning To Become A Racing Driver",
     "description": "3 days of driving with the end goal of passing the racing driver exam. Do I have what it takes?\n\nIf you enjoy the video then please hit that like button!\n\nHelp support the channel over on my Patreon page - https://www.patreon.com/jimmybroadbent\n\nMost the music"
    },
    "defaultAudioLanguage": "en-GB"
   }
  }
 ]
}
SReject commented 4 years ago

if you are attempting to retrieve a field's value, you need to use the value prop:

$json(youtube, etag).value

$json(youtube, items, 0, snippet, title).value

SReject commented 4 years ago

A few notes here:

  1. You should be checking for errors after using /JSONOpen
  2. You either need to use the -d switch with /JSONOpen or call /JSONClose when you are done with a handler
preginald commented 4 years ago

Thanks for the quick reply @SReject