我需要从包含列表中任何单词的 freelancer.com API 获取项目。似乎项目搜索方法or_search_query
中的过滤器不起作用。
<?php
$url = 'https://www.freelancer.com/api/projects/0.1/projects/active/';
$params = array(
'or_search_query' => 'scraper scraping scrap scrapy',
'languages' => array('en'),
);
$params = http_build_query($params);
$params = preg_replace('/%5B[0-9]+%5D/', '%5B%5D', $params); // param[1] -> param[]
$url = $url . '?' . $params;
var_dump(urldecode($url)); // https://www.freelancer.com/api/projects/0.1/projects/active/?or_search_query=scraper scraping scrap scrapy&languages[]=en
$json = json_decode(file_get_contents($url), true);
if ($json) {
foreach ($json['result']['projects'] as $project) {
echo '<a href="https://www.freelancer.com/projects/' . $project['seo_url'] . '">' . $project['title'] . '</a><br />';
}
}
这段代码给了我与“抓取”无关的工作。我究竟做错了什么?