I've been using Parse's REST API for quite a while, but now in an attempt to reduce the amount of requests made to Parse's servers I've started exploring the Cloud Code features which looks quite nice -based on what I've read so far. The fact that you define and run some business logic on Parse's servers looks like a very powerful tool.
However, I haven't even been able to get the basics up and running. I followed this Getting Started Guide but I got stuck when trying to call the "hello" function on the background. Here's what I've done:
- Imported the jar files into the Android Studio project
- Install Parse's powershell command tool
- Created a cloud code directory locally. By default, it creates the
hellofunction in "main.js" - Deployed it
- Run a test on my Android app by call this
hellofunction but it fails to parse the response
Here's the stacktrace of the error:
11-26 08:28:44.499 18299-18299/com.package.appname E/Leo_Debug﹕ Error: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
com.parse.ParseException: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
com.parse.ParseException: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
at com.parse.ParseRequest.connectionFailed(ParseRequest.java:415)
at com.parse.ParseCommand.onResponse(ParseCommand.java:387)
at com.parse.ParseCommand.onResponse(ParseCommand.java:36)
at com.parse.ParseRequest$3.call(ParseRequest.java:295)
at bolts.Task$2.run(Task.java:195)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
This is the cloud code function I'm calling...
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
And this is how I'm making to the call to the function using the Parse SDK for Android...
String clientId = ctx.getString(R.string.parse_app_id);
String clientKey = ctx.getString(R.string.parse_app_api_key);
Map<String,Object> map = new HashMap<String, Object>();
Parse.initialize(ctx, clientId, clientKey);
ParseCloud.callFunctionInBackground("hello", map, new FunctionCallback<String>() {
public void done(String o, ParseException e) {
if(e != null) {
Utils.LogError(e);
}
else{
Utils.Log("ParseCloud.hello: " + o);
}
}
});
The ctx variable is an instance of the "Context" class and Utils it's just a helper class I used when debugging is turn on to print use info to the LogCat.
I haven't been able to find much information around neither on their old Forums Site nor on their dedicated Google Groups. If anyone ran into this issue before any help would be greatly appreciated
response.successfunction. I also tried changing the callback's generic type from a String to a JSONObject on the java code to no avail. Theoparameter always comesnullFunctionCallbackclass there's no way to get the full response