node.js - 由于模块 ibm-watson/auth 无法运行代码
问题描述
以下代码片段来自 watson 音调分析器文档。问题:当我粘贴代码并运行代码时,它运行得非常好。但是,当我将它粘贴到另一个云函数中时,它表明找不到 ibm-watson/auth 模块。不知道为什么它的行为不同?
通常我保存在函数 main (params){} 下。但是,另一个云函数是异步函数,它具有 (require-promise) 的代码。不知道出了什么问题或问题是什么?
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/sdk');
const toneAnalyzer = new ToneAnalyzerV3({
version: '2017-09-21',
authenticator: new IamAuthenticator({
apikey: 'apikey',
}),
serviceUrl: 'url',
});
const text = 'Team, I know that times are tough! Product '
+ 'sales have been disappointing for the past three '
+ 'quarters. We have a competitive product, but we '
+ 'need to do a better job of selling it!';
const toneParams = {
toneInput: { 'text': text },
contentType: 'application/json',
};
toneAnalyzer.tone(toneParams)
.then(toneAnalysis => {
console.log(JSON.stringify(toneAnalysis, null, 2));
})
.catch(err => {
console.log('error:', err);
});
}
解决方案
推荐阅读
- c# - 如何从正则表达式中提取多个值?
- jquery - tinyMCE 显示 html 标签
- swift - Swift NaturalLanguage 框架错误“令牌序列类型长度为 0”
- javascript - set value of custom input before alert popup
- javascript - Render 2 lists in React Native
- javascript - Indicate current page on included Nav.php file
- reactjs - React Native 应用程序中出现奇怪的 ReferenceError
- angular - Map Observable of Array using Observable
- c# - 如何根据 oledb 命令中的当前月份获取月份?
- c# - Getting error parsing ProtoBuf data