Play
Multi-Player
Coins
Community
Settings
Help
Community   Maps   Forum   Mail   Ladders   Clans   Recent Games
Sign In | Sign Up
<< Back to Programming Forum   

Posts 1 - 13 of 13   
Beginner's Question: 11/25/2016 07:27:41


NinjaNic 
Level 57
Report
Hi! I've just been messing around with HTTPRequests and am in no way qualified to do anything. I can't seem to find the format to post json ... in fact, I don't even know what that means, and the internet isn't cooperating.

I've been looking at this wiki page, it seemed like a good start and then tried out one of my WarLight games in browser:

https://www.warlight.net/wiki/Query_game_API
https://www.warlight.net/API/GameFeed?GameID=12269473

I also noticed this:
If you're trying to access it programmatically,
you may POST your username and API Token to this page
in the format Email=your@email.com&APIToken=token


Does that mean I can send a web request directly to a URL with those parameters? This is the part that's troubling me right now. I've tried this, but it doesn't work: (Auth failed error)

https://www.warlight.net/API/GameFeed?GameID=12269473&Email=MY@EMAIL.COM&APIToken=MYTOKEN


What URL do I use to collect data from a game? If anyone could help me I would deeply appreciate it, thanks!
~Nic
Beginner's Question: 11/25/2016 10:05:20


timon92 
Level 62
Report
You use correct URL.

Change your password and use new token.
Beginner's Question: 11/25/2016 15:15:54

Krzysztof 
Level 65
Report

Does that mean I can send a web request directly to a URL with those parameters? This is the part that's troubling me right now. I've tried this, but it doesn't work: (Auth failed error)

https://www.warlight.net/API/GameFeed?GameID=12269473&Email=MY@EMAIL.COM&APIToken=MYTOKEN


What URL do I use to collect data from a game? If anyone could help me I would deeply appreciate it, thanks!
~Nic


Parameters in url string a not "post parameters" so warlight won't read them from it.
You need to set them different way than just adding to URL, you can take a look here:
http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request
Dont know what language do you use, but assuming Java it should be something like that:

      response = HttpRequest
          .create(new URI("https://www.warlight.net/API/GameFeed?GameID=12269473"))
          .body(fromString("Email=MY@EMAIL,APIToken=MYTOKEN"))
          .POST()
          .response();


Edited 11/25/2016 15:23:39
Beginner's Question: 11/25/2016 16:31:41


NinjaNic 
Level 57
Report
Parameters in url string a not "post parameters" so warlight won't read them from it.
You need to set them different way than just adding to URL, you can take a look here:
http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request
Dont know what language do you use, but assuming Java it should be something like that:
      response = HttpRequest
          .create(new URI("https://www.warlight.net/API/GameFeed?GameID=12269473"))
          .body(fromString("Email=MY@EMAIL,APIToken=MYTOKEN"))
          .POST()
          .response();


Thank you! This helped me a lot. But I've seen parameters (username, token) being used directly in the URL before, (not on WarLight.) I'm assuming that is not a "json post?"
Beginner's Question: 11/25/2016 20:33:14


NinjaNic 
Level 57
Report
For my reference and a future reference to anyone using Visual Basic:

Install the Newtonsoft.json package. Also, import these namespaces:
Imports System.IO
Imports System.Net
Imports System.Text
Imports Newtonsoft.Json.Linq

Add this function to your code:
    Function HttpPost() As JObject

        ' JSON Data
        Dim postData As String = "Email=YOUR@EMAIL.COM&APIToken=YOURTOKEN"
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)

        ' HTTP Request
        Dim request As WebRequest = WebRequest.Create("https://www.warlight.net/API/GameFeed?GameID=12269473")
        request.Method = "POST"

        ' Requesting
        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()

        ' Recieving a Response
        dataStream = request.GetResponse.GetResponseStream()
        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()
        dataStream.Close()
        reader.Close()

        Return JObject.Parse(responseFromServer)

    End Function

And here's an example of retrieving data:
        Dim dataName As String = HttpPost.SelectToken("name").ToString ' Will return the game's name.


I know that hardly anyone uses VB anymore, but this may come in handy to someone.
Beginner's Question: 11/25/2016 21:31:56

wct
Level 56
Report
Just a general FYI about parameters and HTTP. Parameters in the URL are generally for GET requests, whereas POST requests generally supply parameters in the content (headers?) of the request. Whether you can include URL parameters in a POST *also*, I'm not sure (it's been a while), but even if you can, that's not generally how it's done. Generally speaking, GETs are very simple and short, with nearly all info provided using the URL. POSTs generally have short URLs and the info is provided separate from the URL (in content/headers/whatever).

Whether or not it's a 'json post' depends a) is it a POST request? b) does it contain JSON?

Not sure if this helps.

Edited 11/25/2016 21:32:43
Beginner's Question: 11/25/2016 22:48:43


NinjaNic 
Level 57
Report
Parameters in the URL are generally for GET requests, whereas POST requests generally supply parameters in the content (headers?) of the request.


Thanks! To me, the "Query Game API" seemed like a GET request, because all that's happening is it sends data to your computer and noting else. (Right?) That's why I was wondering if I could put my email and token directly into the URL.
Beginner's Question: 11/26/2016 19:05:12


NinjaNic 
Level 57
Report
  "error" : "This API can only be used for tournament games, ladder games, games created via the CreateGame API call, games you are in, or coin games."


Aw, man! Why is this?
Beginner's Question: 11/26/2016 19:12:30


TBest 
Level 59
Report
Prevents you from crashing servers :)
Beginner's Question: 11/27/2016 01:29:37

wct
Level 56
Report
Knyte is around, and he knows the most about this API of people I know. Maybe try asking him for some ideas?
Beginner's Question: 11/27/2016 02:18:36


NinjaNic 
Level 57
Report


Here's my final result, for now. It takes a bunch of data from games in any ladder, displays the title, URL, and players with their playing state, and beneath that is a graph of the number of times a certain color was used or its win rate.

I wasn't surprised to find out that red and blue were used more by far in the last 100 games of the 2v2 ladder. However, I thought dark pink would have been used more.

Here's the link to download, if anyone is interested: (You need to be a member)
http://www.mediafire.com/file/2bpd22itzh210nb
Beginner's Question: 11/28/2016 12:00:57


TBest 
Level 59
Report
^That looks awesome and stuff....but I keep getting "Auth failed" :/

I know my login info is correct, so I dunno what is going on.
Beginner's Question: 11/28/2016 23:47:53


NinjaNic 
Level 57
Report
From what I hear, I'm not sure what the problem is, which is not a good sign. I was hoping it would work because there's no way for me to test other accounts, because I only have 1 member account.
Maybe you tried to enter your credentials into the wrong page? The first tab is for email and password, and the second is for email and token.

Letter casing in the email shouldn't matter- I tested it with both all caps and no caps. Did you log in with your main or another account? Did you unpack Newtonsoft.Json.dll and WarLight Game Data.exe?

Edited 11/28/2016 23:50:06
Posts 1 - 13 of 13   

Contact | About WarLight | Play Risk Online | Multiplayer Strategy Game | Challenge Friends, Win Money | Skill Game | Terms of Service