如何通过 Parse4J 连接到托管的 Parse-Server?
How can I connect to a hosted Parse-Server over Parse4J?
我希望能够使用 Parse4J 库(https://github.com/thiagolocatelli/parse4j/) to connect to a hosted Parse-Server. I want to use https://parseapi.back4app.com 作为 API 端点。它们提供了可靠的 Parse 托管解决方案。
代码:
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");
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();
}
}
});
}
}
依赖关系:
<dependencies>
<dependency>
<groupId>com.github.thiagolocatelli</groupId>
<artifactId>parse4j</artifactId>
<version>1.4</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>
我尝试通过提供本地版本覆盖 Maven 存储库,即 1.4-FIXED
并将 ParseConstants.java 中的 API_ENDPOINT 值更改为指向 https://parseapi.back4app.com
,这是我的数据库托管:
public class ParseConstants {
public static final String API_ENDPOINT = "https://parseapi.back4app.com";
public static final String API_VERSION = "1";
public static final String HEADER_CONTENT_TYPE = "Content-Type";
public static final String HEADER_APPLICATION_ID = "X-Parse-Application-Id";
public static final String HEADER_REST_API_KEY = "X-Parse-REST-API-Key";
public static final String HEADER_MASTER_KEY = "X-Parse-Master-Key";
public static final String HEADER_SESSION_TOKEN = "X-Parse-Session-Token";
public static final String CONTENT_TYPE_JSON = "application/json";
public static final String FIELD_OBJECT_ID = "objectId";
public static final String FIELD_CREATED_AT = "createdAt";
public static final String FIELD_UPDATED_AT = "updatedAt";
public static final String FIELD_SESSION_TOKEN = "sessionToken";
public static int MAX_PARSE_FILE_SIZE = 10485760;
}
我收到一个 ParseException:
ParseException [code=109, error=unauthorized]
at org.parse4j.command.ParseResponse.getParseError(ParseResponse.java:122)
at org.parse4j.command.ParseResponse.getException(ParseResponse.java:78)
at org.parse4j.ParseQuery.find(ParseQuery.java:598)
at org.parse4j.ParseQuery.find(ParseQuery.java:469)
at org.parse4j.ParseQuery.get(ParseQuery.java:377)
at org.parse4j.ParseQuery$GetInBackgroundThread.run(ParseQuery.java:452)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
这意味着我的连接没有正确初始化:
/**
* You must call Parse.initialize before using the Parse library.
*/
public static final int NOT_INITIALIZED = 109;
通过更彻底地研究 Parse4J 库,我可以做更多的事情。然而,在这一点上,我迷路了。我能做什么?
感谢 Parse4J 的开发人员,我能够通过将我的依赖项更新到最新的快照版本 1.5-SNAPSHOT
然后更新我的初始化方法以包含包含自定义 API端点。这在大约 8 个月前是可能的,但文档没有提及任何关于使用最新版本的信息,因为它还不是官方版本。我使用 https://parseapi.back4app.com 得到了这个工作。他们提供可靠的 Parse 托管解决方案,但您可以将其替换为您自己的 URI。我认为新版本应该即将发布...
<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>
初始化方法:
Parse.initialize(applicationId, restAPIKey, "https://parseapi.back4app.com");
在此处查看文档:https://github.com/thiagolocatelli/parse4j/commit/4113b422631c364488bc51152da8b071542e8159
我希望能够使用 Parse4J 库(https://github.com/thiagolocatelli/parse4j/) to connect to a hosted Parse-Server. I want to use https://parseapi.back4app.com 作为 API 端点。它们提供了可靠的 Parse 托管解决方案。
代码:
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");
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();
}
}
});
}
}
依赖关系:
<dependencies>
<dependency>
<groupId>com.github.thiagolocatelli</groupId>
<artifactId>parse4j</artifactId>
<version>1.4</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>
我尝试通过提供本地版本覆盖 Maven 存储库,即 1.4-FIXED
并将 ParseConstants.java 中的 API_ENDPOINT 值更改为指向 https://parseapi.back4app.com
,这是我的数据库托管:
public class ParseConstants {
public static final String API_ENDPOINT = "https://parseapi.back4app.com";
public static final String API_VERSION = "1";
public static final String HEADER_CONTENT_TYPE = "Content-Type";
public static final String HEADER_APPLICATION_ID = "X-Parse-Application-Id";
public static final String HEADER_REST_API_KEY = "X-Parse-REST-API-Key";
public static final String HEADER_MASTER_KEY = "X-Parse-Master-Key";
public static final String HEADER_SESSION_TOKEN = "X-Parse-Session-Token";
public static final String CONTENT_TYPE_JSON = "application/json";
public static final String FIELD_OBJECT_ID = "objectId";
public static final String FIELD_CREATED_AT = "createdAt";
public static final String FIELD_UPDATED_AT = "updatedAt";
public static final String FIELD_SESSION_TOKEN = "sessionToken";
public static int MAX_PARSE_FILE_SIZE = 10485760;
}
我收到一个 ParseException:
ParseException [code=109, error=unauthorized]
at org.parse4j.command.ParseResponse.getParseError(ParseResponse.java:122)
at org.parse4j.command.ParseResponse.getException(ParseResponse.java:78)
at org.parse4j.ParseQuery.find(ParseQuery.java:598)
at org.parse4j.ParseQuery.find(ParseQuery.java:469)
at org.parse4j.ParseQuery.get(ParseQuery.java:377)
at org.parse4j.ParseQuery$GetInBackgroundThread.run(ParseQuery.java:452)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
这意味着我的连接没有正确初始化:
/**
* You must call Parse.initialize before using the Parse library.
*/
public static final int NOT_INITIALIZED = 109;
通过更彻底地研究 Parse4J 库,我可以做更多的事情。然而,在这一点上,我迷路了。我能做什么?
感谢 Parse4J 的开发人员,我能够通过将我的依赖项更新到最新的快照版本 1.5-SNAPSHOT
然后更新我的初始化方法以包含包含自定义 API端点。这在大约 8 个月前是可能的,但文档没有提及任何关于使用最新版本的信息,因为它还不是官方版本。我使用 https://parseapi.back4app.com 得到了这个工作。他们提供可靠的 Parse 托管解决方案,但您可以将其替换为您自己的 URI。我认为新版本应该即将发布...
<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>
初始化方法:
Parse.initialize(applicationId, restAPIKey, "https://parseapi.back4app.com");
在此处查看文档:https://github.com/thiagolocatelli/parse4j/commit/4113b422631c364488bc51152da8b071542e8159