2

I need to get projects from freelancer.com API which contains any words from a list. It seems that or_search_query filter in project search method does not work.

<?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 />';
    }
}

This code gives to me jobs which are not relevant for 'scraping'. What am I doing wrong?

user4157124
  • 2,809
  • 13
  • 27
  • 42
Artem
  • 517
  • 1
  • 7
  • 24

1 Answers1

0

Assuming that you are using the API correctly, when are you making the curl request? I do not see it in the code. You're forming the URL in $url variable then decoding the url and then using json_decode to decode that information. What is being returned from there? can you provide it?

If you are actually in fact not making any curl request I advise you to use the library Guzzle: http://docs.guzzlephp.org/en/latest/ It will make your life easier when debugging. I hope you're using a debugger instead of var_dumps because that would make things much clearer to you.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
Zatara7
  • 241
  • 2
  • 11