简体   繁体   中英

How to call the Parse.com API from a LibGDX java implementation?

I have created a simple standalone game using Java/libgdx. I am now trying to make calls using Parse.com API service.

Question: What is the simplest way to make a call to Parse.com API from within a java application created on the back of LibGDX?

Found a great answer to this question here:

http://pastie.org/private/mfb3keufurzp5thfszndcq#2-3,5,9,37-109

You don't need to use the API from Parse.com. I followed these instruction, created a very simple Java class and imported Java's own Net and IO libraries. Connects via HTTPS using an app id and key, so make sure you hide your code before putting it out there.

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);

Use their REST API .

See this question for suggestions of how to interact with REST APIs in Java.

If you want to use the Libgdx Net API to be cross platform(*), you can use that to access the Parse REST API. Specifically you'll want to use the Net.HttpRequest to make REST calls and handle the response.

The Libgdx Net API is more "callback" oriented, which often fits better into a Libgdx application than the more thread-oriented standard Java network APIs.

(*) Android and Desktop Java share a compatible network API, so the Libgdx Net API is mostly for compatibility with the HTML (and iOS?) backend(s).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM