-
Notifications
You must be signed in to change notification settings - Fork 113
How can I connect to a hosted Parse-Server over Parse4J? #81
Copy link
Copy link
Open
Description
Many people have been asking how to do this so I thought I'd just post some sample code with a working solution. Could we sticky this, or at least update the main README? I got this working using https://parseapi.back4app.com as an API endpoint. They provide a solid Parse hosting solution. This is just a proof of concept in a single Java class. I'm sure it would be more useful in a Spring or Springboot application.
import org.parse4j.Parse;
import org.parse4j.ParseException;
import org.parse4j.ParseObject;
import org.parse4j.ParseQuery;
import org.parse4j.callback.GetCallback;
/**
* Created by Martin on 3/27/2017.
*/
public class Parse4JStarter {
public static void main(String[] args) {
Parse.initialize("applicationId","restAPIKey", "https://parseapi.back4app.com");
if (Parse.getApplicationId() != null) {
System.out.println("ParseConnection successful! " + Parse.getApplicationId());
try {
queryPost();
} catch (ParseException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static void queryPost() throws Exception {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
query.getInBackground("4tD9TIIIhv", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
System.out.println("ParseObject printed successfully! " + object);
} else {
e.printStackTrace();
}
}
});
}
}
Make sure your dependency includes the latest snapshot build, 1.5-SNAPSHOT. I also included some logging dependencies because my console told me to include them for some reason:
<dependencies>
<dependency>
<groupId>com.github.thiagolocatelli</groupId>
<artifactId>parse4j</artifactId>
<version>1.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels