如何使用algolia android将数据推送到我的索引

时间:2017-08-02 09:22:21

标签: android algolia

我在将数据推送到索引时遇到问题。我的代码如下:

Client client = new Client("APP_ID", "SEARCH_ID");

            Index myIndex = client.initIndex("test");
            JSONObject jsonObject = null;
            try {
                jsonObject = new JSONObject()
                        .put("name", "Jimmie")
                        .put("username", "Barninger")
            } catch (JSONException e) {
                e.printStackTrace();
            }
            myIndex.addObjectAsync(jsonObject, null);

但是没有任何反应,并且我的信息中心中没有可见的数据。我做错了什么?

2 个答案:

答案 0 :(得分:1)

要了解更多信息,请使用以下内容替换addobjectAsync行:

index.addObjectAsync(object, new CompletionHandler() {
    @Override
    public void requestCompleted(JSONObject content, AlgoliaException error) {
        if (error != null) {
            // Check what is the error Here
        }
    }
}

答案 1 :(得分:1)

我不得不更改之前为const req = { body: { "object": "page", "entry": [{ "id": "488064221540488", "time": 1501681094769, "messaging": [{ "sender": { "id": "1559711167437676" }, "recipient": { "id": "488064221540488" }, "timestamp": 1501681094579, "message": { "mid": "mid.$cAAHhEUCp_UVj1HBXs1do8-BMiIPg", "seq": 559, "text": "Thunder." } }] }] } }; const id = req.body.entry[0].messaging[0].sender.id; console.log(id, parseInt(id));的api密钥。我将其更改为SEARCH_ID

ADMIN_API_KEY

这是因为只搜索API密钥只能用于搜索,而Admin API密钥可以更改,删除或添加对象。

完整的代码现在是:

Client client = new Client("APP_ID", "ADMIN_API_KEY");
相关问题