|
Joined: Mar 2015
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Mar 2015
Posts: 7 |
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:
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: 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?)
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 https://developer.riotgames.com and with option e combined with www.developer.riotgames.com and just 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
Last edited by sumsar1812; 07/03/15 02:04 AM.
|
|
|
|
Joined: Sep 2014
Posts: 259
Fjord artisan
|
Fjord artisan
Joined: Sep 2014
Posts: 259 |
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
|
|
|
|
Joined: Mar 2015
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Mar 2015
Posts: 7 |
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 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 ?
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
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
}
}
Last edited by FroggieDaFrog; 07/03/15 04:30 PM.
|
|
|
|
Joined: Mar 2015
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Mar 2015
Posts: 7 |
%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
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
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: 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: var a = ["value1", "value2", "value3"]
a[0] is value1
a[1] is value2
a[2] is value3 so if we nest items: var a = {"key1": ["value1", "value2", "value3"] }
a["key1"] is the array ["value1", "value2", "value3"]
a["key1"][0] is: value1
|
|
|
|
Joined: Mar 2015
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Mar 2015
Posts: 7 |
Ah alright I think i got it. Atleast I think, but I donĀ“t understand why this wont return the right thing. {"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 $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
Last edited by sumsar1812; 11/03/15 04:57 PM.
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
Could I get the url from where that data is coming from?
|
|
|
|
Joined: Mar 2015
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Mar 2015
Posts: 7 |
|
|
|
|
Joined: Jan 2004
Posts: 1,359
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,359 |
Stats is not an array, access it by $json(hisAPI,games,0,stats,win)
|
|
|
|
Joined: Mar 2015
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Mar 2015
Posts: 7 |
Ah I see, I thought it would still take it as an array with 1 index. Thank you
|
|
|
|
|