SReject / JSON-For-Mirc

JSON parser for mIRC
20 stars 6 forks source link

handling twitch apiv5 #47

Closed DreadfullyDespized closed 6 years ago

DreadfullyDespized commented 6 years ago

Example from twitch on how to connect to apiv5 curl -H 'Accept: application/vnd.twitchtv.v5+json' \ -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \ -H 'Authorization: OAuth cfabdegwdoklmawdzdo98xt2fo512y' \ -X GET 'https://api.twitch.tv/kraken/channel'

Working example in Python. Headers = { "Accept": "application/vnd.twitchtv.v5+json", "Client-ID": MySettings.ClientId, "Authorization": "OAuth {}".format(MySettings.AccessToken) } r = Parent.GetRequest("https://api.twitch.tv/kraken/streams/{0}".format(MySettings.ChannelID,), Headers)

My mirc attempt with JSON v1.0.4000 jsonopen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized JSONHttpHeader test Accept application/vnd.twitchtv.v5+json JSONHttpHeader test Client-ID %clientid JSONHttpHeader test Authorization OAuth %oauth JSONHttpFetch test echo $json(test,status).value

The mirc example never gets any data and errors out.

SReject commented 6 years ago

Are you sure its Authorization OAuth .... and not Authorization Bearer ... as OAuth2's auth tokens are usually bearer tokens

Looking at the docs, this is wrong. v5 requires OAuth but the new twitch api uses Bearer.

I'll need more info to go on: /jsondebug on

DreadfullyDespized commented 6 years ago

The echo $json(test,status).value is what is erroring out. insufficient paramters for echo. Here is what I got with jsongebug on.

Debug now enabled mIRC v7.52 32bit SReject/JSONForMirc v1.0.4000 [NormalMode]

-> /JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456695300000 -> $jfm_ComInit <- Already Initialized <- NAME_INUSE -> /JSONHttpHeader test Accept application/vnd.twitchtv.v5+json -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456698400000 -> $jfm_ComInit <- Already Initialized -> $jfm_Exec(JSON:test,httpSetHeader,Accept,application/vnd.twitchtv.v5+json) -> $jfm_GetError <- HTTP_NOT_PENDING <- HTTP_NOT_PENDING <- HTTP_NOT_PENDING -> /JSONHttpHeader test Client-ID clientid -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456712500000 -> $jfm_ComInit <- Already Initialized -> $jfm_Exec(JSON:test,httpSetHeader,Client-ID,clientid) -> $jfm_GetError <- HTTP_NOT_PENDING <- HTTP_NOT_PENDING <- HTTP_NOT_PENDING -> /JSONHttpHeader test Authorization OAuth oauth -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456735900000 -> $jfm_ComInit <- Already Initialized -> $jfm_Exec(JSON:test,httpSetHeader,Authorization,OAuth oauth) -> $jfm_GetError <- HTTP_NOT_PENDING <- HTTP_NOT_PENDING <- HTTP_NOT_PENDING -> /JSONHttpFetch test -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456765600000 -> $jfm_ComInit <- Already Initialized -> $jfm_Exec(JSON:test,parse) -> $jfm_GetError <- PARSE_NOT_PENDING <- PARSE_NOT_PENDING <- PARSE_NOT_PENDING -> $JSON(test,status).value -> $com(JSON:test,walk,1,bool,$false,bstr,$2,dispatch* JSON:test:514568062000000) -> $jfm_Exec(JSON:test:514568062000000,type) -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456817100000 <- Result stored in &SReject/JSONForMirc/Tmp51456817100000 -> $jfm_Exec(JSON:test:514568062000000,value) -> $jfm_TmpBVar <- &SReject/JSONForMirc/Tmp51456834300000 <- Result stored in &SReject/JSONForMirc/Tmp51456834300000 <- 400 -> /JSONClose JSON:test:514568062000000 -> Closed JSON:test:514568062000000 <- All matching handles closed

SReject commented 6 years ago

you are getting a NAME_INUSE error

call /JSONClose test, rerun your test script and update the output please

Use this test script to get a debug output: /json_test Your_Client_Id Your_OAuth_Token

alias json_test {
  if ($0 !== 2) {
    echo 04 -a Missing Client id or OAuth token: /json_test $1-
  }
  jsondebug on
  if ($JSON(test)) {
    JSONClose test
  }
  JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized
  if ($JSONError) {
    echo 04 -a JSONOpen Error: $v1
    JSONClose test
    return
  }
  JSONHttpHeader test Accept application/vnd.twitchtv.v5+json
  JSONHttpHeader test Client-ID $1
  JSONHttpHeader test Authorization OAuth $2
  if ($JSONError) {
    echo 04 -a JSON Header Error: $v1
    JSONClose test
    return
  }
  JSONHttpFetch test
  if ($JSONError) {
    echo 04 -a JSON Fetch Error: $v1
    JSONClose test
    return
  }
  echo $json(test,status).value
  JSONClose test
}

On another note:

  1. To format code, you can also wrap code in 3 backticks: ``` code ```
  2. On twitch I'm always in mirchelp (#mirchelp from mIRC)
DreadfullyDespized commented 6 years ago

Copied and paste what you provided and added the information for the clientid/oauth

Debug now enabled
mIRC v7.52 32bit
SReject/JSONForMirc v1.0.4000 [NormalMode]
-
-> $JSON(test)
    <- HANDLER_NOT_FOUND
-> /JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52005417100000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52005420300000
    -> $jfm_create(JSON:test,http,&SReject/JSONForMirc/Tmp52005420300000,1,)
        <- Created JSON:test
    <- Created test (as com JSON:test)
-> /JSONHttpHeader test Accept application/vnd.twitchtv.v5+json
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52005428100000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Accept,application/vnd.twitchtv.v5+json)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52005439000000
        <- Result stored in &SReject/JSONForMirc/Tmp52005439000000
    <- Stored Header 'Accept: application/vnd.twitchtv.v5+json'
-> /JSONHttpHeader test Client-ID clientid
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52005448400000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Client-ID,clientid)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52005459300000
        <- Result stored in &SReject/JSONForMirc/Tmp52005459300000
    <- Stored Header 'Client-ID: clientid'
-> /JSONHttpHeader test Authorization OAuth ouath
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52005471800000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Authorization,OAuth ouath)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52005487500000
        <- Result stored in &SReject/JSONForMirc/Tmp52005487500000
    <- Stored Header 'Authorization: OAuth ouath'
-> /JSONHttpFetch test
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52005506200000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,parse)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52005553100000
        <- Result stored in &SReject/JSONForMirc/Tmp52005553100000
    <- Http Data retrieved
-> $JSON(test,status).value
    -> $com(JSON:test,walk,1,bool,$false,bstr,$2,dispatch* JSON:test:520055734000000)
    -> $jfm_Exec(JSON:test:520055734000000,type)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52005581200000
        <- Result stored in &SReject/JSONForMirc/Tmp52005581200000
    -> $jfm_Exec(JSON:test:520055734000000,value)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52005598400000
        <- Result stored in &SReject/JSONForMirc/Tmp52005598400000
    <- 400
-> /JSONClose JSON:test:520055734000000
    -> Closed JSON:test:520055734000000
    <- All matching handles closed
SReject commented 6 years ago

You are now getting a 400 error back from twitch; the following test script will output what twitch returned as the HTTP response:

/json_test your_client_id your_oauth_token

alias json_test {
  if ($0 !== 2) {
    echo 04 -a Missing Client id or OAuth token: /json_test $1-
  }
  jsondebug on
  if ($JSON(test)) {
    JSONClose test
  }
  JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized
  if ($JSONError) {
    echo 04 -a JSONOpen Error: $v1
    JSONClose test
    return
  }
  JSONHttpHeader test Accept application/vnd.twitchtv.v5+json
  JSONHttpHeader test Client-ID $1
  JSONHttpHeader test Authorization OAuth $2
  if ($JSONError) {
    echo 04 -a JSON Header Error: $v1
    JSONClose test
    return
  }
  JSONHttpFetch test
  if ($JSONError) {
    echo 04 -a JSON Fetch Error: $v1
    JSONClose test
    return
  }
  echo -a $json(test).HttpBody
  JSONClose test
}
DreadfullyDespized commented 6 years ago

That is really odd. Here is the output.

Debug now enabled
mIRC v7.52 32bit
SReject/JSONForMirc v1.0.4000 [NormalMode]
-
-> $JSON(test)
    <- HANDLER_NOT_FOUND
-> /JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52171662500000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52171664000000
    -> $jfm_create(JSON:test,http,&SReject/JSONForMirc/Tmp52171664000000,1,)
        <- Created JSON:test
    <- Created test (as com JSON:test)
-> /JSONHttpHeader test Accept application/vnd.twitchtv.v5+json
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52171673400000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Accept,application/vnd.twitchtv.v5+json)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52171684300000
        <- Result stored in &SReject/JSONForMirc/Tmp52171684300000
    <- Stored Header 'Accept: application/vnd.twitchtv.v5+json'
-> /JSONHttpHeader test Client-ID clientid
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52171695300000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Client-ID,clientid)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52171709300000
        <- Result stored in &SReject/JSONForMirc/Tmp52171709300000
    <- Stored Header 'Client-ID: clientid'
-> /JSONHttpHeader test Authorization OAuth oauth
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52171723400000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Authorization,OAuth oauth)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52171742100000
        <- Result stored in &SReject/JSONForMirc/Tmp52171742100000
    <- Stored Header 'Authorization: OAuth oauth'
-> /JSONHttpFetch test
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52171770300000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,parse)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52171825000000
        <- Result stored in &SReject/JSONForMirc/Tmp52171825000000
    <- Http Data retrieved
-> $JSON(test).HttpBody
    -> $jfm_Exec(JSON:test,httpBody)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52171854600000
        <- Result stored in &SReject/JSONForMirc/Tmp52171854600000
    <- {"error":"Bad Request","status":400,"message":"Channel identifier \"dreadfullydespized\" is in an invalid format"}
{"error":"Bad Request","status":400,"message":"Channel identifier \"dreadfullydespized\" is in an invalid format"}
-> /JSONClose test
    -> Closed JSON:test
    <- All matching handles closed

Though if I use the apiv3 method it works... The code that works.

alias json_test2 {
  if ($0 !== 2) {
    echo 04 -a Missing Client id or OAuth token: /json_test $1-
  }
  jsondebug on
  if ($JSON(test)) {
    JSONClose test
  }
  JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized
  if ($JSONError) {
    echo 04 -a JSONOpen Error: $v1
    JSONClose test
    return
  }
  JSONHttpHeader test Client-ID $1
  if ($JSONError) {
    echo 04 -a JSON Header Error: $v1
    JSONClose test
    return
  }
  JSONHttpFetch test
  if ($JSONError) {
    echo 04 -a JSON Fetch Error: $v1
    JSONClose test
    return
  }
  echo -a $json(test).HttpBody
  JSONClose test
}

The results.

Debug now enabled
mIRC v7.52 32bit
SReject/JSONForMirc v1.0.4000 [NormalMode]
-
-> $JSON(test)
    <- HANDLER_NOT_FOUND
-> /JSONOpen -uw test https://api.twitch.tv/kraken/channels/dreadfullydespized
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52183710900000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52183714000000
    -> $jfm_create(JSON:test,http,&SReject/JSONForMirc/Tmp52183714000000,1,)
        <- Created JSON:test
    <- Created test (as com JSON:test)
-> /JSONHttpHeader test Client-ID clientid
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52183723400000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,httpSetHeader,Client-ID,clientid)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52183731200000
        <- Result stored in &SReject/JSONForMirc/Tmp52183731200000
    <- Stored Header 'Client-ID: clientid'
-> /JSONHttpFetch test
    -> $jfm_TmpBVar
        <- &SReject/JSONForMirc/Tmp52183742100000
    -> $jfm_ComInit
        <- Already Initialized
    -> $jfm_Exec(JSON:test,parse)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52183779600000
        <- Result stored in &SReject/JSONForMirc/Tmp52183779600000
    <- Http Data retrieved
-> $JSON(test).HttpBody
    -> $jfm_Exec(JSON:test,httpBody)
        -> $jfm_TmpBVar
            <- &SReject/JSONForMirc/Tmp52183798400000
        <- Result stored in &SReject/JSONForMirc/Tmp52183798400000
    <- {"mature":true,"status":"† mIRC botting - so Shiney so Wow so Chrome! †","broadcaster_language":"en","display_name":"DreadfullyDespized","game":"Creative","language":"en","_id":50895536,"name":"dreadfullydespized",
"created_at":"2013-10-31T04:23:30Z","updated_at":"2018-05-06T22:02:53Z","partner":false,"logo":"https://static-cdn.jtvnw.net/jtv_user_pictures/dreadfullydespized-profile_image-e49aee05a03b9a5c-300x300.jpeg","video_banner":null,"profile_banner":"https://static-cdn.jtvnw.net/jtv_user_pictures/bd26f8587f2d4be3-profile_banner-480.png","profile_banner_background_color":null,"url":"https://www.twitch.tv/dreadfullydespized","views":128901,"followers":806,"_links":{"self":"https://api.twitch.tv/kraken/channels/dreadfullydespized","follows":"https://api.twitch.tv/kraken/channels/dreadfullydespized/follows","commercial":"https://api.twitch.tv/kraken/channels/dreadfullydespized/commercial","stream_key":"https://api.twitch.tv/kraken/channels/dreadfullydespized/stream_key","chat":"https://api.twitch.tv/kraken/chat/dreadfullydespized","features":"https://api.twitch.tv/kraken/channels/dreadfullydespized/features","subscriptions":"https://api.twitch.tv/kraken/channels/dreadfullydespized/subscriptions","editors":"https://api.twitch.tv/kraken/channels/dreadfullydespized/editors","teams":"https://api.twitch.tv/kraken/channels/dreadfullydespized/teams","videos":"https://api.twitch.tv/kraken/channels/dreadfullydespized/videos"},"delay":null,"banner":null,"background":null}
{"mature":true,"status":"† mIRC botting - so Shiney so Wow so Chrome! †","broadcaster_language":"en","display_name":"DreadfullyDespized","game":"Creative","language":"en","_id":50895536,"name":"dreadfullydespized","created_at":"2013-10-31T04:23:30Z","updated_at":"2018-05-06T22:02:53Z","partner":false,"logo":"https://static-cdn.jtvnw.net/jtv_user_pictures/dreadfullydespized-profile_image-e49aee05a03b9a5c-300x300.jpeg","video_banner":null,"profile_banner":"https://static-cdn.jtvnw.net/jtv_user_pictures/bd26f8587f2d4be3-profile_banner-480.png","profile_banner_background_color":null,"url":"https://www.twitch.tv/dreadfullydespized","views":128901,"followers":806,"_links":{"self":"https://api.twitch.tv/kraken/channels/dreadfullydespized","follows":"https://api.twitch.tv/kraken/channels/dreadfullydespized/follows","commercial":"https://api.twitch.tv/kraken/channels/dreadfullydespized/commercial","stream_key":"https://api.twitch.tv/kraken/channels/dreadfullydespized/stream_key","chat":"https://api.twitch.tv/kraken/chat/dreadfullydespized","features":"https://api.twitch.tv/kraken/channels/dreadfullydespized/features","subscriptions":"https://api.twitch.tv/kraken/channels/dreadfullydespized/subscriptions","editors":"https://api.twitch.tv/kraken/channels/dreadfullydespized/editors","teams":"https://api.twitch.tv/kraken/channels/dreadfullydespized/teams","videos":"https://api.twitch.tv/kraken/channels/dreadfullydespized/videos"},"delay":null,"banner":null,"background":null}
-> /JSONClose test
    -> Closed JSON:test
    <- All matching handles closed
SReject commented 6 years ago

With twitch's apiv5, you'll need to translate the usernames to a userid/channelid before you can make calls to the api for the specified user/channel. To do so is explained in the twitch apiv5 docs

Im closing this issue as it is not an issue with JSONForMirc; feel free to continue commenting/posting questions of which you need help with.

DreadfullyDespized commented 6 years ago

Thank you so much!!!!