Ibm cloud MessageResponse在Watson对话中返回空指针
Ibm cloud MessageResponse在Watson对话中返回空指针,ibm-cloud,ibm-watson,chatbot,watson-conversation,Ibm Cloud,Ibm Watson,Chatbot,Watson Conversation,MessageResponse给出一个NullPointerException ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_09_20); // Credentials of Workspace of Conversation service.setApiKey("API_KEY"); service.setUsernameAndPassword("USER
MessageResponse
给出一个NullPointerException
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_09_20);
// Credentials of Workspace of Conversation
service.setApiKey("API_KEY");
service.setUsernameAndPassword("USERNAME", "PASSWORD");
MessageRequest newMessage = new MessageRequest.Builder()
.inputText(request.getQuery())
.build();
// Workspace ID of Conversation current workspace
String workspaceId = "WORKSPACEID";
service.setSkipAuthentication(true);
MessageResponse response = service.message(workspaceId, newMessage)
.execute();
据IBM开发人员(@German):“Watson服务目前使用Basic Auth,因此您将使用用户名和密码而不是api_密钥。为了获得凭据,您需要将您要使用的服务(例如问答)绑定到Bluemix应用程序。” 检查以下示例。 请尝试从中使用以下代码:
- 你可以看到官员使用沃森对话
- 请参阅使用Watson服务的入门指南(步骤5)
- 对话服务不使用
api\u密钥
,而是使用用户名
和密码
您的代码片段中有两个错误:
1. <使用对话时不需要代码>setApiKey()。
1. <代码>服务。设置Kipauthentication(true)将指示SDK忽略服务凭据,因此不会在每次请求时将其发送到服务器
您只需要删除行service.setSkipAuthentication(true)代码>
如果这对您有帮助,请标记答案,并遵循上的“如何回答”。但是考虑通过@德国ATTANASIO来验证答案,他解释了为什么你的代码不起作用,他在IBM专注于Watson Developer Cloud(我们用Watson编码的SDK)工作,你的答案确切地解释了用户需要知道什么。向上投票@帕克,考虑把这个答案标记为正确。我赞成你的观点,因为它链接到我们希望用户看到的重要材料。
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_05_26);
service.setUsernameAndPassword("<username>", "<password>"); //Please make sure if this username and password is the Service Credentials from the Service that you have created to use Conversation
InputData input = new InputData.Builder("Hi").build();
MessageOptions options = new MessageOptions.Builder(workspaceId).input(input).build();
// sync
MessageResponse response = service.message(options).execute();
System.out.println(response);
MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();
MessageResponse response = service.message(WORKSPACE_ID,newMessage).execute();
context = response.getContext();
System.out.println(response);
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_09_20);
// Credentials of Workspace of Conversation
// BTW: This are not your Bluemix credentials!
service.setUsernameAndPassword("USERNAME", "PASSWORD");
MessageRequest newMessage = new MessageRequest.Builder()
.inputText("Hi! this is my first message to Watson")
.build();
MessageResponse response = service.message("WORKSPACEID", newMessage)
.execute();
System.out.println(response);