我有一个调用 Watson 对话服务的 IBM Cloud Function (OpenWhisk)。我们正在使用 JAVA JAVA SDK ( https://github.com/watson-developer-cloud/java-sdk ) 的文档表明将从绑定中获取凭据。
当我列出绑定时,我得到了这个:
>bx wsk action get talksmall parameters
ok: got action talksmall, displaying field parameters
[
{
"key": "__bx_creds",
"value": {
"conversation": {
"credentials": "Credentials-SmallTalk",
"instance": "<INSTANCE>",
"password": "<PASSWORD>",
"url": "https://gateway.watsonplatform.net/conversation/api",
"username": "<USERNAME>"
}
}
}
]
但是当我像这样使用 SDK 时:
Conversation conversationService = new Conversation(Conversation.VERSION_DATE_2017_05_26);
我收到一个错误
{
"error": "An error has occured while invoking the action (see logs for details): java.lang.IllegalArgumentException: apiKey or username and password were not specified"
}
当我添加该行时:
conversationService.setUsernameAndPassword(userName, password);
有用。也许 VCAP_Service 绑定方式不适用于 Cloud Functions ?Cloud Function 在相同的 IBM Cloud 组织和空间中运行。