1

我想调用 Apify 演员并通过调用 Apify API 来指定参数值。

演员是位于此处的 Google Search Results Scraper

这是文档说用作queriesAPI 调用有效负载中的对象属性名称的地方。

下表显示了由其输入模式定义的参与者 INPUT 字段的规范。当使用 API 运行 actor 时,可以 [...] 在 JSON 对象中提供这些字段。在文档中阅读更多内容。

...

搜索查询或 URL

Google 搜索查询(例如纽约市的食物)和/或完整 URL(例如https://www.google.com/search?q=food+NYC)。

每行输入一项。

可选
类型:字符串

JSON 示例
"queries": "Hotels in NYC
  Restaurants in NYC
  https://www.google.com/search?q=restaurants+in+NYC"

运行我的 Google Apps 脚本代码后,我希望看到searchQueries.term参数发生如下变化。

Apify——我期望看到的
"searchQuery": {
  "term": "Banks in Phoenix", // what I am trying to change to by API call
  // [...]
},

但我实际得到的是与上次手动运行actor时相同的参数值。如下。

Apify——我实际看到的
"searchQuery": {
  "term": "CPA firms in Newark", // remaining from last time I ran the actor manually
  // [...]
},

这是我从 Google Apps 脚本运行的代码。

代码.gs
const runSearch = () => {
  const apiEndpoint= `https://api.apify.com/v2/actor-tasks/<MY-TASK-NAME>/run-sync?token=<MY-TOKEN>`
  const formData = {
    method: 'post',
    queries: 'Banks in Phoenix',
  };
  const options = {
    body: formData,
    headers: {
      'Content-Type': 'application/json',
    },
  };
  UrlFetchApp.fetch(apiEndpoint, options,);
}

我究竟做错了什么?

4

1 回答 1

0

您缺少对象payload中的属性request

改变:
queries: 'Banks in Phoenix',
至:
payload: {
  queries: 'Banks in Phoenix',
}
代码.gs
const runSearch = () => {
  const apiEndpoint= `https://api.apify.com/v2/actor-tasks/<MY-TASK-NAME>/run-sync?token=<MY-TOKEN>`
  const formData = {
    method: 'post',
    payload: {
      queries: 'Banks in Phoenix',
    },
  };
  const options = {
    body: formData,
    headers: {
      'Content-Type': 'application/json',
    },
  };
  UrlFetchApp.fetch(apiEndpoint, options,);
}
于 2020-04-07T03:13:42.240 回答