代码之家  ›  专栏  ›  技术社区  ›  NoUsername9

Apify API请求主体

  •  1
  • NoUsername9  · 技术社区  · 6 年前

    在以下API请求中,我的请求主体应该是什么?

    API请求
    POST https://private-anon-xxxxxxxx-apify2prod.apiary-proxy.com/v2/actor-tasks/testttt~hedge-funds-scraper/run-sync?token=XXXXX
    
    Request Headers
    content-type: application/json
    content-length: 18
    
    Request Body
    {
      "bar": "foo"
    }
    

    我的目标是通过使用Apify API发送服务器请求来远程运行任务。 Here is the documentation I'm referencing for my API call.

    我期望的结果是一个服务器响应,其中包含我手动运行任务时获得的相同数据集。具体来说,该数据集如下。

    预期结果
    [{
      "url": "https://en.wikipedia.org/wiki/List_of_hedge_funds",
      "pageTitle": "List of hedge funds - Wikipedia",
      "links": [
        {
          "firmName": "Bridgewater Associates",
          "firmUrl": "/wiki/Bridgewater_Associates",
          "hq": "Westport, CT",
          "hqUrl": "/wiki/United_States",
          "aum": "$132,050"
        },
        {
          "firmName": "Renaissance Technologies",
          "firmUrl": "/wiki/Renaissance_Technologies",
          "hq": "East Setauket, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$110,000"
        },
        {
          "firmName": "Man Group",
          "firmUrl": "/wiki/Man_Group",
          "hq": "London",
          "hqUrl": "/wiki/United_Kingdom",
          "aum": "$62,000"
        },
        {
          "firmName": "AQR Capital Management",
          "firmUrl": "/wiki/AQR_Capital_Management",
          "hq": "Greenwich, CT",
          "hqUrl": "/wiki/United_States",
          "aum": "$60,840"
        },
        {
          "firmName": "Two Sigma Investments",
          "firmUrl": "/wiki/Two_Sigma_Investments",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$42,900"
        },
        {
          "firmName": "Millennium Management",
          "firmUrl": "/wiki/Millennium_Management,_LLC",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$38,776"
        },
        {
          "firmName": "Elliott Management",
          "firmUrl": "/wiki/Elliott_Management",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$37,769"
        },
        {
          "firmName": "BlackRock",
          "firmUrl": "/wiki/BlackRock",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$32,909"
        },
        {
          "firmName": "Citadel LLC",
          "firmUrl": "/wiki/Citadel_LLC",
          "hq": "Chicago, IL",
          "hqUrl": "/wiki/United_States",
          "aum": "$32,243"
        },
        {
          "firmName": "Davidson Kempner Capital Management",
          "firmUrl": "/wiki/Davidson_Kempner_Capital_Management",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$30,880"
        },
        {
          "firmName": "Viking Global Investors",
          "firmUrl": "/wiki/Viking_Global_Investors",
          "hq": "Greenwich, CT",
          "hqUrl": "/wiki/United_States",
          "aum": "$30,000"
        },
        {
          "firmName": "Baupost Group",
          "firmUrl": "/wiki/Baupost_Group",
          "hq": "Boston, MA",
          "hqUrl": "/wiki/United_States",
          "aum": "$28,900"
        },
        {
          "firmName": "D.E. Shaw & Co.",
          "firmUrl": "/wiki/D.E._Shaw_%26_Co.",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$28,676"
        },
        {
          "firmName": "Farallon Capital",
          "firmUrl": "/wiki/Farallon_Capital",
          "hq": "San Francisco, CA",
          "hqUrl": "/wiki/United_States",
          "aum": "$27,600"
        },
        {
          "firmName": "Marshall Wace",
          "firmUrl": "/wiki/Marshall_Wace",
          "hq": "London",
          "hqUrl": "/wiki/United_Kingdom",
          "aum": "$27,100"
        },
        {
          "firmName": "The Children's Investment Fund Management",
          "firmUrl": "/wiki/The_Children%27s_Investment_Fund_Management",
          "hq": "London",
          "hqUrl": "/wiki/United_Kingdom",
          "aum": "$27,100"
        },
        {
          "firmName": "Wellington Management Company",
          "firmUrl": "/wiki/Wellington_Management_Company",
          "hq": "Boston, MA",
          "hqUrl": "/wiki/United_States",
          "aum": "$22,000"
        },
        {
          "firmName": "Winton Group",
          "firmUrl": "/wiki/Winton_Group",
          "hq": "London",
          "hqUrl": "/wiki/United_Kingdom",
          "aum": "$22,100"
        },
        {
          "firmName": "Capula Investment Management",
          "firmUrl": "/wiki/Capula_Investment_Management",
          "hq": "London",
          "hqUrl": "/wiki/United_Kingdom",
          "aum": "$19,800"
        },
        {
          "firmName": "York Capital Management",
          "firmUrl": "/wiki/York_Capital_Management",
          "hq": "New York City, NY",
          "hqUrl": "/wiki/United_States",
          "aum": "$18,500"
        }
      ]
    }] 
    

    下面是我得到的实际结果的截图。请注意201响应代码和响应正文中突出显示的部分,内容如下:

    { bar: 'foo' }

    实际结果

    enter image description here

    我做错了什么?我的请求正文应该是什么?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Vasek Tobey Vlcek    6 年前

    确保您指定了 outputRecordKey 正确输入URL参数。它需要匹配由参与者生成并存在于键值存储中的一些密钥。请注意,您只能通过这种方式访问键值存储,而不能访问数据集。如果你需要从默认数据集中获取数据,那么你需要在运行后手动查询它,或者选择异步运行并使用响应中的信息来定位数据集。查看文档中的这些端点:

    https://docs.apify.com/api/v2#/reference/actor-tasks/last-run-object-and-its-storages