问题
I want to insert some data in my Custom-Object Class, but I get the error: "Forbidden. Need user.". Here's my code:
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("user", username);
fields.put("name", ada.getTitle());
fields.put("type", ada.getType());
fields.put("text", ada.getText());
fields.put("status", ada.getStatus());
QBCustomObject qbCustomObject = new QBCustomObject();
qbCustomObject.setClassName("Ada");
qbCustomObject.setFields(fields);
qbCustomObject.setUserId(userId);
QBCustomObjects.createObject(qbCustomObject, new QBCallback() {
@Override
public void onComplete(Result result) {
// get creates score
QBCustomObjectResult qbCustomObjectResult = (QBCustomObjectResult) result;
QBCustomObject qbCustomObject = qbCustomObjectResult.getCustomObject();
}
@Override
public void onComplete(Result result, Object o) {
}
});
Thanks very much!
回答1:
In order to create/update/delete object you have to be signed in as user.
Sign-In
final QBUser user = new QBUser("testuser", "testpassword");
QBUsers.signIn(user, new QBCallbackImpl() {
@Override
public void onComplete(Result result) {
if (result.isSuccess()) {
QBUserResult qbUserResult = (QBUserResult) result;
} else {
handleErrors(result);
}
}
});
来源:https://stackoverflow.com/questions/15282585/quickblox-error-with-custom-object-android