簡體   English   中英

使用Node.js(watson-developer-cloud模塊)發送AlchemyData新聞查詢

[英]Sending an AlchemyData News query using Node.js (watson-developer-cloud module)

我目前正在使用watson-developer-cloud Node.js SDK使用Node.js,在發送包含實體的查詢時遇到問題。

這是我的代碼:

// require watson's node sdk and fs
var watson = require('watson-developer-cloud');
var fs = require('fs');

// Define output file
var outputJSONFile = '/home/vagrant/Desktop/node/dir/data.json';

// Create alchemy_data_news object using our api_key
var alchemy_data_news = watson.alchemy_data_news({
  api_key: ''
});

// Define params for the query and what values to return
// Accepted returne values:
// docs.alchemyapi.com/v1.0/docs/full-list-of-supported-news-api-fields
var params = {
  start: 'now-1m',
  end: 'now',
  count: 2,
  qs: ['q.enriched.url.enrichedTitle.entities.entity.text=apple'],
  return: ['enriched.url.url,enriched.url.title']
};

// Call getNews method and return json
alchemy_data_news.getNews(params, function (err, news) {
  if (err) {
    console.log('error:', err);
  } else {
    fs.writeFile(outputJSONFile, JSON.stringify(news, null, 2), function(err)   {
      if (err) {
        console.log('WriteFile Error:', err);
      } else {
        console.log("JSON saved to " + outputJSONFile);
      }
    });
  }
});

我仍在嘗試找出如何使用params對象發送實體參數。

在研究一些代碼時,我遇到了qs,因此我一直在使用它進行測試,但我一點都沒有成功。

任何建議,不勝感激。

PS:我想通過:
q.enriched.url.enrichedTitle.entities.entity.text = apple q.enriched.url.enrichedTitle.entities.entity.type = company

如果查看AlchemyDataNewsnode-sdk源代碼 ,您將看到頂級參數作為查詢字符串發送。
然后params映射應該是:

var params = {
  start: 'now-1m',
  end: 'now',
  count: 2,
  return: ['enriched.url.url,enriched.url.title'],
  // fields here 
  'q.enriched.url.enrichedTitle.entities.entity.text': 'apple',
  'q.enriched.url.enrichedTitle.entities.entity.type': 'company'
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM