人格洞察输入var nodejs

时间:2016-09-03 15:20:30

标签: node.js ibm-cloud personality-insights

var PersonalityInsightsV2 = require('watson-developer-cloud/personality-insights/v2');

var personality_insights = new PersonalityInsightsV2({
  username: '<username>',
  password: '<password>'
});

personality_insights.profile({
  text: '<?php echo $_Session['description'];?>',
  language: 'en' },
  function (err, response) {
    if (err)
      console.log('error:', err);
    else
      console.log(JSON.stringify(response, null, 2));
});

它不会显示任何内容。我也已经完成了npm watson cloud并保存了它,我已经把我的凭据放在git上了。我错过了什么?我是初学者但很想在我的页面上使用它!

1 个答案:

答案 0 :(得分:1)

以下是在本地运行它的步骤,因为您是初学者,我将从头开始。

创建一个新文件夹并根据需要为其命名。把这些文件放在那里。

命名第一个文件:FOLLOWk-1

填写index.js<YOUR-USERNAME><YOUR-PASSWORD>变量。

<YOUR-100-UNIQUE-WORDS>

创建另一个文件并将其命名为:var express = require('express'); var app = express(); var http = require('http').Server(app); var cfenv = require("cfenv"); var appEnv = cfenv.getAppEnv(); http.listen(appEnv.port, appEnv.bind); var PersonalityInsightsV2 = require('watson-developer-cloud/personality-insights/v2'); var personality_insights = new PersonalityInsightsV2({ username: '<YOUR-USERNAME>', password: '<YOUR-PASSWORD>' }); personality_insights.profile({ text: "<YOUR-100-UNIQUE-WORDS>", language: 'en' }, function (err, response) { if (err) console.log('error:', err); else console.log(JSON.stringify(response, null, 2)); });

将这些内容放在那里

package.json

打开您的终端并{ "name": "myWatsonApp", "version": "1.0.0", "description": "A Watson Personality Insights application", "main": "index.js", "scripts": { "start": "node index.js" }, "dependencies": { "cfenv": "^1.0.3", "express": "^4.13.4", "watson-developer-cloud": "^2.2.0" } } 到您刚创建的文件夹的根目录。

运行命令:cd

然后运行命令npm install

您的应用程序将继续运行,您将看到在npm start

中打出的个性洞察电话的输出