mIRC Homepage
Posted By: sumsar1812 get requests returning 504 - 07/03/15 01:49 AM
This might not be a 100% mIRC script related question but not sure where else to ask.

I have just started creating my own bot for twitch.tv and I wan't to use Riot games API to get data about the streamer.

I have tried for multiple hours without any luck so here is what I have tired:

Code:
on *:TEXT:!Rank:#: { 
  sockclose http
  sockopen -e http developer.riotgames.com 80
}
on *:SockOpen:http: {
  msg $chan connection made..
  sockwrite http GET /https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/27028362/entry?api_key=4dceac67-7859-4fe6-8b32-3dc93f604d86 HTTP/1.1
  msg $chan request send  
}

on *:SockRead:http: {
  msg $chan recv data
  if ($sockerr > 0) return 
  :nextread 
  sockread %temp 
  if ($sockbr == 0) return 
  msg $chan %temp
  goto nextread 
}



this is the get request I got from the Riot API:
Code:
https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/27028362/entry?api_key=4dceac67-7859-4fe6-8b32-3dc93f604d86

and request headers(not sure if these are relevant?)

Code:

User-Agent: Riot-Games-Developer-Portal
Accept-Language: en-US
Accept-Charset: ISO-8859-1,utf-8
Origin: https://developer.riotgames.com



First of I am not sure what my host should be(in sockopen). I have tried with
Code:
https://developer.riotgames.com
and with option e combined with
Html:
www.developer.riotgames.com
and just
Html:
developer.riotgames.com


I have also tried to use euw.api.pvp.net but that gave an error(couldn't make the connection)

I have also tried a few different things for the GET request with no luck(like with or without the "euw.api.pvp.net" part and "https"

So if I get to establish the connection and send the request I get an error 504(timeout) after 30-60 secounds

here is the riot api documentation if it is needed to get a better understanding of what my problem is: https://developer.riotgames.com/


I hope you get the essence of what my problem is and can give me some help to solve it.

Sorry for bad english, it is pretty late and english isn't my native language
Posted By: Sakana Re: get requests returning 504 - 07/03/15 07:48 AM
You need to use port 443, and your sockopen event seems way off.. but don't waste time using sockets with APIs. Use the JSON parser made by SReject smile
Posted By: sumsar1812 Re: get requests returning 504 - 07/03/15 04:14 PM
Yea okay I looked it up and I can see the json parser is alot simpler, but I still have a few troubles
I have tried this now

Code:
on *:TEXT:!Rank:#: {
  JSONClose api
  JSONOpen -uwd api https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/27028362/entry?api_key=4dceac67-7859-4fe6-8b32-3dc93f604d86
  JSONURLOption api User-Agent Riot-Games-Developer-Portal
  JSONURLOption api Accept-Language en-US
  JSONURLOption api Accept-Charset ISO-8859-1,utf-8
  JSONGet api https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/27028362/entry?api_key=4dceac67-7859-4fe6-8b32-3dc93f604d86
  %temp = $json(api,"27028362","queue")
  IF (%temp) {
    msg $chan %temp
  }
  ELSE {
    msg $chan test
  }
}


but %temp is not containing anything ? I have also tried $json(api).error and .errortext nether containing anything ?
Posted By: FroggieDaFrog Re: get requests returning 504 - 07/03/15 04:25 PM
Code:
on *:TEXT:!Rank:#:{
  JSONOpen -ud api https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/27028362/entry?api_key=4dceac67-7859-4fe6-8b32-3dc93f604d86

  %temp = $json(api, 27028362, 0, queue)
  if (%temp) {
    msg $chan %temp
  }
  else {
    msg $chan test
  }

}
Posted By: sumsar1812 Re: get requests returning 504 - 07/03/15 06:07 PM
Quote:
%temp = $json(api, 27028362, 0, queue)


what is the ,0 in here? I saw it in another example too but wasn't sure what it ment
Posted By: FroggieDaFrog Re: get requests returning 504 - 07/03/15 07:04 PM
JSON contains two types of structures that can be nested: key-value pairing(donated with {}'s), and indexed arrays(donated with []):

Key-value Pairing: These gets referenced by a specified name:
Code:
var a = {"key1": "value1", "key2": "value2"}
a["key1"] is value1
a["key2"] is value2


Indexed Arrays: These get referenced by an index; that is by 'the Nth item'. Indexes, unlike general mIRC, start at 0, not 1:
Code:
var a = ["value1", "value2", "value3"]
a[0] is value1
a[1] is value2
a[2] is value3


so if we nest items:
Code:
var a = {"key1": ["value1", "value2", "value3"] }
a["key1"] is the array ["value1", "value2", "value3"]
a["key1"][0] is: value1
Posted By: sumsar1812 Re: get requests returning 504 - 11/03/15 03:48 PM
Ah alright I think i got it. Atleast I think, but I donĀ“t understand why this wont return the right thing.

Code:
{"summonerId":19669750,"games":[{"gameId":2008668968,"invalid":false,"gameMode":"CLASSIC","gameType":"MATCHED_GAME","subType":"NORMAL","mapId":11,"teamId":200,"championId":53,"spell1":14,"spell2":4,"level":30,"ipEarned":122,"createDate":1426085938698,"fellowPlayers":
[{"summonerId":27285317,"teamId":100,"championId":92},
{"summonerId":20454275,"teamId":200,"championId":131},
{"summonerId":22733251,"teamId":100,"championId":67},
{"summonerId":29588954,"teamId":200,"championId":222},
{"summonerId":21352251,"teamId":100,"championId":25},
{"summonerId":372146,"teamId":200,"championId":59},
{"summonerId":40872533,"teamId":100,"championId":31},
{"summonerId":27678276,"teamId":200,"championId":103},
{"summonerId":19106723,"teamId":100,"championId":114}],"stats":{"level":18,"goldEarned":14852,"numDeaths":4,"minionsKilled":37,"championsKilled":4,"goldSpent":13820,"totalDamageDealt":48325,"totalDamageTaken":29057,"team":200,"win":true,..."playerPosition":4}},{"gameId":...


I can get the gameId and teamId with no problem. ($json(hisAPI,games,0,teamId) and $json(hisAPI,games,0,gameId) )

but I got a problem that I want to see the "win" I have tried this
Code:
$json(hisAPI,games,0,stats,0,win)


But this displays nothing. It is the first index of games and the first index of stats(or am i wrong?)

Thanks again

edit hisAPI is ofc the json handle
Posted By: FroggieDaFrog Re: get requests returning 504 - 11/03/15 05:23 PM
Could I get the url from where that data is coming from?
Posted By: sumsar1812 Re: get requests returning 504 - 11/03/15 05:26 PM
Here
Posted By: Loki12583 Re: get requests returning 504 - 11/03/15 07:27 PM
Stats is not an array, access it by $json(hisAPI,games,0,stats,win)
Posted By: sumsar1812 Re: get requests returning 504 - 11/03/15 07:29 PM
Ah I see, I thought it would still take it as an array with 1 index. Thank you
© mIRC Discussion Forums