• Register

An Island survival sandbox game. Build up your resources, build your shelter, fish and hunt for food and just stay alive. Early development, missions/achievements/story to come later.

Post news Report RSS Parse.com Restful API in LibGDX Game

A look at Parse.com (online data storage) with a Java LibGDX game, push and pull data such as highscores via this cloud service.

Posted by on

To have a break from fish AI, this evening decided to set up a highscore board feature as a test case for JSON and online storage for Endure. There are many companies offering this sort of service to game/app developers but I have heard good things about Parse so thought I would try them first.

So I Signed up for Parse.com a very neat data-store for mobiles and web applications, they provide example projects for JavaScript, Unity, Android and other platforms, SDK's and sample projects so you can hit the ground running.

The best thing is the price... free!

Features

  • Requests: 1 million/month
  • Pushes: 1 million/month
  • Burst Limit: 20/second

There are paid plans available but while in development phase this is perfect.

Scores Table
After creating a new app I created a new class named 'score', using the simple GUI added score and user to the table:

I did try out the Android sample project but without your app being Android as expected there was no way to use the .Jar libraries that Parse provide, but they do offer a great Restful API to POST and GET your data. The website is clean and very clear:


Custom Parse Class
I wrote a very simple Java class and imported Java's own Net and IO libraries, did not take long to get some scores in and out of the service. Connects via HTTPS using an app id and key, so make sure you hide your code before putting it out there.

LibGDX has its own Net library so I also gave this a go as my code looked messy, this too was simple to get working, I have some speed tests to run yet but happy to be able to push and pull data for free and with no real hassle.

I will not go through my code put post the class for you to see, important lines here are:

httpPost.setHeader("X-Parse-Application-Id", app_id);
httpPost.setHeader("X-Parse-REST-API-Key", app_key);

conn.setRequestProperty("X-Parse-Application-Id", app_id);
conn.setRequestProperty("X-Parse-REST-API-Key", app_key);

While looking how others use Parse with Java I saw a lot of complaints about unauthorized errors on data requests, Parse provides many different keys and you have to set and use the right ones depending how you are connecting.

Full Source Code (My Parse Class)

Here I called the class as soon as the game started, a hard coded score is pushed to the 'score' table and then all scores are returned:

Lots of testing left to do with this and of course will need to ask/store the username (@twitter_tag) of the current player. I will use this for the upcoming fishing competition and keep a track of all the fish caught.

Also will need to use a JSON library to properly generate the string that is post (containing username and score) and also parse the results into objects so they can be displayed in game.

Thanks for reading.

Comments
Guest
Guest

can give me source code of login and sign up users in parse rest api using java

thanks

Reply Good karma Bad karma0 votes
carelesslabs Author
carelesslabs

Hello, everything you need to set this up lives here:

Parse.com

When creating object use a JSONobject:

JSONObject obj = new JSONObject();
obj.put("username", user);


Reply Good karma+1 vote
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

carelesslabs Author
carelesslabs

If you are really stuck I will try and make a new tutorial soon :D

Reply Good karma+1 vote
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
Endure
Platforms
Windows, Mac, Linux
Creator
carelesslabs
Engine
libGDX
Contact
Send Message
Release date
Game watch
Follow
News
Browse
News
New
Post news
Report
Report
Share
Related Games
Endure
Endure Adventure
Related Engines
libGDX
libGDX Commercial