首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >IBM Watson UnAuthorized

IBM Watson UnAuthorized
EN

Stack Overflow用户
提问于 2020-04-12 21:52:19
回答 1查看 64关注 0票数 0

我实现了IBM watson Assistant,它在android调试中工作得很好。当我构建一个签名的apk时,问题就来了。上面总是写着未经授权。我不认为这是关键,因为它在调试模式下工作得很好。我需要一些帮助,因为这个项目正在进行中。到目前为止,我尝试的是在IBM云中更改密钥,并尝试了其他密钥,但它引发了未发现的异常,我认为这是由错误的密钥引起的。我是不是应该允许IBM cloud中的某些东西用于签名的apk?或者是否有来自签名apk的证书,我必须上传到IBM云中?即时通信工具使用IBM watson Assistant v2

代码语言:javascript
运行
复制
private Assistant watsonAssistant;
private Response<SessionResponse> watsonAssistantSession;

private void createServices() {
    watsonAssistant = new Assistant("2020-04-01", new IamAuthenticator(getString(R.string.assistant_apikey)));
    watsonAssistant.setServiceUrl(getString(R.string.assistant_url));
}

private void sendMessage(){
    Thread thread = new Thread(() -> {
                    try {
                        if (watsonAssistantSession == null) {
                            ServiceCall<SessionResponse> call = watsonAssistant.createSession(new CreateSessionOptions.Builder().assistantId(getString(R.string.normal_assistant_id)).build());
                            watsonAssistantSession = call.execute();
                        }
                        MessageInput input = new MessageInput.Builder()
                                .text(userInput)
                                .build();
                        MessageOptions options = new MessageOptions.Builder()
                                .assistantId(getString(R.string.normal_assistant_id))
                                .input(input)
                                .sessionId(watsonAssistantSession.getResult().getSessionId())
                                .build();
                        Response<MessageResponse> response = watsonAssistant.message(options).execute();
                        if (response.getResult().getOutput() != null && !response.getResult().getOutput().getGeneric().isEmpty()) {
                            List<RuntimeResponseGeneric> responses = response.getResult().getOutput().getGeneric();
                            for (RuntimeResponseGeneric r : responses) {
                                switch (r.responseType()) {
                                    case "text":
                                        aiResponse = r.text();
                                        aiConversationList.add(new AIConversation(r.text(), "ai", System.currentTimeMillis()));
                                        break;
                                    default:
                                        Log.e("Error", "Unhandled message type");
                                }
                            }
                            runOnUiThread(() -> {
                                sendConvoToServer(userInput, aiResponse);
                                txtWelcomeAI.setVisibility(View.VISIBLE);
                                aiAdapter.notifyItemInserted(aiConversationList.size() - 1);
                                userInputTxt.setEnabled(true);
                                pRecyclerView.scrollToPosition(aiConversationList.size() - 1);
                                aStatus.setText("online");

                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.e("IBM_EXCEPTION", e.toString());
                        aiConversationList.add(new AIConversation("Oops! Something went wrong", "ai", System.currentTimeMillis()));
                        aiAdapter.notifyItemInserted(aiConversationList.size() - 1);
                        runOnUiThread(() -> {
                            pRecyclerView.scrollToPosition(aiConversationList.size() - 1);
                            aStatus.setText("online");
                            userInputTxt.setEnabled(true);
                        });
                    }
                });
                thread.start();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-13 05:16:56

如果其他人在调试和发布apks之间遇到像我这样的问题,试着检查一下你是否做过混淆。如果是这样,那么混淆可能是一个问题。至少对我来说是这样。因此,要么在应用程序级别禁用build.gradle模糊处理,要么在proguard-rules中添加一些规则

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61172512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档