Zodian.6597:

I’m currently a pre CS major (finishing up 2nd year) in university and I’m pretty fluent with Java and Python, but haven’t done much outside of data structures as far as actual programming goes. I want to start making some tools using the GW2 api, but I’m not entirely sure where to start. Are there any guides for getting into this? Is it as simple as just downloading the library I want then importing it in a class and calling get methods on the object fields?

rodadams.5963:

Is it as simple as just downloading the library I want then importing it in a class and calling get methods on the object fields?

You just described an extremely large portion of all programming. The trick is knowing which method of which object from which library to call with what arguements.

However, most any url fetcher library will do, (you’ll want to look at how to add additional headers for the auth stuff), and then a json parser library. Retrieve page, feed it through a json parser, do stuff with resulting data. You’ll have greater challenges figuring out how to do what you want to with the data than you will getting the data.

Elrey.5472:

No idea about java, but in python 3.4.3 is quite simple to run scripts to access the API. Here’s an example that I use to get me information of items:

#Library needed
from urllib import request
#List of items to access
TotalItems = [1,2,6,11,24] #Check full list of items at http://api.guildwars2.com/v2/items

#Create local file if doesn't exists
Createlocalfile = open("fromgw2api.txt", "a")
Createlocalfile.close()

#Main Function
def Checkitems():
	global TotalItems
	Total = str(len(TotalItems))
	print("[START] - There's: "+Total+" items.")
	for i in TotalItems: #For each item in my list
		print("Saving the ID: "+str(i)+" from a total of "+Total+" items.")
		Respuesta = request.urlopen("http://api.guildwars2.com/v2/items /"+str(i)+"?lang=es").read() #Opens the item website and reads it
		#The next line is an spanish fix for some letters like áéíóúñ
		Respuesta = str(Respuesta)[2:-1].replace("\\xc3\\xb3", "ó").replace("\\xc3\\xad","í").replace("\\xc3\\xa1","á").replace("\\xc3\\xb1","ñ").replace("\\xc3\\xa9","é").replace("\\xc3\\xba","ú")
		#Then save the info that it did just read into the local file
		writing = open("fromgw2api.txt", 'a')
		writing.write(str(Respuesta)+"\n")
		writing.close()
	print("[END] - All items saved")

#Run the script
Checkitems()

Edit: That should give you a glimpse of how to start. You would end up with the items information in json structure. Using that information should be easy for you.

JaxomNC.5381:

In Java, I would simply recommand to get JSON-P API (AKA JSR 353), either the reference (1.0) implementation at https://java.net/projects/jsonp/downloads or the latest update (1.0.4) at http://search.maven.org/#search%7Cga%7C1%7Cjavax.json

With this JAR it’s quite easy to parse the JSON returned by the various endpoints. The rest is just basic java.net.URL handling plus some string manipulation in order to construct the URL. You can also try to use one of the 3rd party library available around here and some Apache HTTPClient library but really it’s not needed… plain Java + JSON-P is largely enough to make it work.

I’ve made test examples using the Quaggan and World APIs at (articles and code comment in French, you can get sources at the bottom of each article, tests using JavaFX not Swing, JDK8 is mandatory as I use lambdas):

Even though the exemple use JavaFX, it should not be hard to addapt them to use Swing, SWT, whatever…

I’ve got a 3rd entry planned about the Dye endpoint but as my desktop computer is currently crashed I cannot post the article and code yet.

I am currently working on a 4th entry to attempt to use the authentication endpoints.