简体   繁体   English

如何限制搜索结果Google JSON API

[英]How to limit search results google json api

I'm working on adding a search function to a discord bot I'm making and I want to limit the number of search results from Google's JSON API. 我正在努力将搜索功能添加到正在制作的Discord机器人中,我想限制Google JSON API的搜索结果数量。 My code is as follows: 我的代码如下:

const {google} = require('googleapis');
const customsearch = google.customsearch('v1');

async function runSample (options) {
  console.log(options);
  const res = await customsearch.cse.list({
    cx: options.cx,
    q: options.q,
    auth: options.apiKey
  });
  console.log(res.data);
  return res.data;
}

else if(command == "SEARCH") {
    console.log("Executed: " + command + ":" + args + " for " + sender.tag);
    const options = {
      q: args,
      apiKey: redacted,
      cx: redacted
    };
    var searchResult = runSample(options).catch(console.error);

    currentChannel.send(searchResult)

After this, I would like to simplify the results into something like the name of the result and the corresponding URL that I can send in the discord server. 之后,我想将结果简化为类似结果的名称以及可以在不和谐服务器中发送的相应URL。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

I would like to inform you that gathering search results from Google is disallowed as stated in the ToS from Google. 谨通知您,如Google ToS中所述,不允许从Google收集搜索结果。 They're not giving out an API for it. 他们没有为此提供API。

Want to read more? 想了解更多吗? Here's a Stack Overflow question. 这是一个堆栈溢出问题。

However when you're looking for the Custom Search API, you've 100 requests every day for free, but when you're looking for more requests, you've to pay as stated here . 但是,当您在寻找Custom Search API时,每天有100个免费请求,但是当您在寻找更多请求时,您必须按照此处所述进行付款。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM