Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I connect to a hosted Parse-Server over Parse4J? #81

Open
SeloSlav opened this issue Mar 28, 2017 · 2 comments
Open

How can I connect to a hosted Parse-Server over Parse4J? #81

SeloSlav opened this issue Mar 28, 2017 · 2 comments

Comments

@SeloSlav
Copy link

SeloSlav commented Mar 28, 2017

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>
@SeloSlav SeloSlav changed the title Working solution query from hosted Parse server How can I connect to a hosted Parse-Server over Parse4J? Mar 30, 2017
@cheetah90
Copy link

Hi @santafebound !
Thanks for the sample code. A quick question: since parse4j 1.5-SNAPSHOT does not seem to exist in any public repo, do we have to build the jar locally and put it in the local maven repo ourselves?
Thanks
Allen

@SeloSlav
Copy link
Author

SeloSlav commented Jul 9, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants