首页 > 解决方案 > 我按照 Watson Tone 分析器的 api 文档无济于事 - 无法连接两个端点

问题描述

我有一个 Watson Tone 云服务启动并运行,我正在尝试将它链接到我的 index.js 文件。但是它似乎不想连接。

下面的代码:

const ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');

const toneAnalyzer = new ToneAnalyzerV3({
	version: '2017-09-21',
	iam_apikey: 'omoNirDx1MUQwCdlHTQ-5Fxklx2_c0dUVAyMFIItFLty',
	url: 'http://watson-row-analyser.eu-gb.cf.appdomain.cloud/#'
});
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 = {
	tone_input: { text: text },
	content_type: 'application/json'
};

toneAnalyzer
	.tone(toneParams)
	.then((toneAnalysis) => {
		console.log(JSON.stringify(toneAnalysis, null, 2));
	})
	.catch((err) => {
		console.log('error:', err);
	});

当前错误代码:

Marcs-MacBook-Pro:npm-global marcwatts$ node index1.js
error: { Not Found: Not Found
    at formatError (/Users/marcwatts/Desktop/mxw817/DBTestApp/npm-global/node_modules/watson-developer-cloud/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:111:17)
    at /Users/marcwatts/Desktop/mxw817/DBTestApp/npm-global/node_modules/watson-developer-cloud/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:259:19
    at process._tickCallback (internal/process/next_tick.js:68:7)
  name: 'Not Found',
  code: 404,
  message: 'Not Found',
  body:
   '"<!DOCTYPE html>\\n<html lang=\\"en\\">\\n<head>\\n<meta charset=\\"utf-8\\">\\n<title>Error</title>\\n</head>\\n<body>\\n<pre>Cannot POST /</pre>\\n</body>\\n</html>\\n"',
  headers:
   { 'x-backside-transport': 'FAIL FAIL',
     connection: 'close',
     'transfer-encoding': 'chunked',
     'content-security-policy': 'default-src \'none\'',
     'content-type': 'text/html; charset=utf-8',
     date: 'Sat, 06 Jul 2019 15:32:34 GMT',
     'x-content-type-options': 'nosniff',
     'x-powered-by': 'Express',
     'x-global-transaction-id': 'ba9308f85d20bf12a70673ff' } }

Watson 的 api 链接:

https://cloud.ibm.com/apidocs/tone-analyzer?code=node

代码 404 表示未找到。请求的项目或参数不存在。我错过了什么?

标签: node.jsibm-watson

解决方案


推荐阅读