运行节点v10 ibm-watson v5.1.0
尝试获取语音转文本令牌时出错。
{ “ message”:“必须设置身份验证器。”, “ name”:“错误”, “ stack”:“错误:必须设置身份验证器。\ n在AuthorizationV1.BaseService(/nodejsAction/VuncPM95/node_modules/ibm-cloud-sdk-core/lib/base-service.js:66:19)\n在新位置Object.token的AuthorizationV1(/nodejsAction/VuncPM95/node_modules/ibm-watson/authorization/v1.js:44:28)\n(/nodejsAction/VuncPM95/services/stt.js:17:32)\n to-text_token(/nodejsAction/VuncPM95/index.js:42:54)\n在Object.exec(/nodejsAction/VuncPM95/index.js:33:73)\n在Promise(/nodejsAction/VuncPM95/index.js :10:16)\ n在新Promise()\ n在NodeActionRunner.main [作为userScriptMain](/nodejsAction/VuncPM95/index.js:9:12)\n在Promise(/nodejsAction/runner.js:73: 35)\ n在新的Promise()“ }
当尝试 打字稿3.6.4
{ “ message”:“必须设置身份验证器。”, “ name”:“错误”, “ stack”:“错误:必须设置身份验证器。\ n在te(eval在initializeActionHandler(/nodejsAction/runner.js:57:23),:22:45665)\ n在新t(eval在initializeActionHandler(/ nodejsAction) /runner.js:57:23),:16:49145)\ n在Object.token(eval在initializeActionHandler(/nodejsAction/runner.js:57:23),:22:44594)\ n在讲话到text_token(在初始化动作处理程序(/nodejsAction/runner.js:57:23),:22:43617)\ n(在Object.exec(在initializeActionHandler(/nodejsAction/runner.js:57:23)处评估),:22:43498 )\ n在Promise(eval在initializeActionHandler(/nodejsAction/runner.js:57:23),:22:43038)\ n在新Promise()\ n在NodeActionRunner.a [作为userScriptMain](eval在initializeActionHandler(/ nodejsAction / runner.js:57:23),:22:43016)\ n在Promise(/nodejsAction/runner.js:73:35)\n在新Promise()“ }
export const SpeechToText = {
token: (params: WatsonParams) => {
const sttCredentials = Object.assign(
{
username: params.speechToTextUsername, // or hard-code credentials here
password: params.speechToTextPassword,
iam_apikey: params.speechToTextIamApikey, // if using an RC service
url: params.speechToTextUrl ? params.speechToTextUrl : SpeechToTextV1.URL
},
vcapServices.getCredentials('speech_to_text') // pulls credentials from environment in bluemix, otherwise returns {}
);
const sttAuthService = new AuthorizationV1(sttCredentials);
return Observable.create((observer) => {
sttAuthService.getToken(function(err, response) {
if (err) {
console.log('Error retrieving token: ', err);
observer.error('Error retrieving token...');
} else {
const token = response.token || response;
if (params.speechToTextIamApikey) {
observer.next({ accessToken: token, url: sttCredentials.url });
} else {
observer.next({ token: token, url: sttCredentials.url });
}
observer.complete();
}
});
});
}
}
期望它返回令牌。
答案 0 :(得分:1)
身份验证在v5中已更改。参见MIGRATION-V5
SDK服务构造函数现在接受
Authenticator
个用于验证请求的对象。构造函数不再接受username
和password
之类的个人凭据。
这是API reference中的一个例子。
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const speechToText = new SpeechToTextV1({
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
url: '{url}',
});