如何在QuickBlox自定义表中创建新记录

时间:2013-10-28 09:19:21

标签: android quickblox

想要在已经创建的QuickBlox自定义表中创建新记录。 我遵循指南Url 并使用以下方法,这里我使用我的表名

HashMap<String, Object> fields = new HashMap<String, Object>();

    fields.put("User ID",String.valueOf(myID));
    fields.put("senderLoginID", ""+mylogin.toString());
    fields.put("receiverLoginID", ""+friendLogin.toString());
    fields.put("messages", messageString);

    fields.put("isRead", false);


QBCustomObject qbCustomObject = new QBCustomObject();
qbCustomObject.setClassName("Movie");  // your Class name
qbCustomObject.setFields(fields);
QBCustomObjects.createObject(qbCustomObject, new QBCallbackImpl() {
    @Override
    public void onComplete(Result result) {
        if (result.isSuccess()) {
            QBCustomObjectResult qbCustomObjectResult = (QBCustomObjectResult) result;
            QBCustomObject qbCustomObject = qbCustomObjectResult.getCustomObject();
            Log.d("New record: ",newCustomObject.toString());
        } else {
            Log.e("Errors",result.getErrors().toString());
        }
    }
});

错误获得赞

** '{"errors":{"base":["Forbidden. Need user."]}}'
… Request has been completed with error: [base Forbidden. Need user.]

1 个答案:

答案 0 :(得分:1)

首先,你不需要使用这个

fields.put("User ID",String.valueOf(myID));

此字段将根据您的令牌信息在服务器上填写

接下来,您必须登录才能创建记录, 只是做下一个

http://quickblox.com/developers/SimpleSample-users-android#Sign_In_.26_Social_authorization