Closed jadersbr closed 4 years ago
Hi @jadersilvabr ,
Thanks for the feedback! It seems the problem is in the class itself, as converting the $options
array to apicalypse is missing a few quotes. If you execute the IGDB->apicalypse($options)
method you will get this result:
fields id,slug,name;
where slug = starcraft-brood-war;
Your error message said that this query is missing a quote starting at starcraft. It seems when the value is a string it has to be enclosed between quotes.
I'll fix this issue and push the fix to the repo.
Okay, so the issue is fixed. I have extended your example as below:
<?php
require 'src/class.igdb.php';
// Instantiate the class
$IGDB = new IGDB('...');
$options = array(
'fields' => 'id, slug, name',
'where' => array(
array(
'field' => 'slug',
'postfix' => '=',
'value' => 'starcraft-brood-war'
),
array(
'field' => 'rating',
'postfix' => '>',
'value' => 80
)
)
);
var_dump($IGDB->apicalypse($options));
try {
$result = $IGDB->game($options);
var_dump($result);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
Now, the apicalypse method will return this:
fields id,slug,name;
where slug = "starcraft-brood-war" & rating > 80;
String values will be enclosed by quotes, integers will be ignored. The script will return this object:
array (size=1)
0 =>
object(stdClass)[2]
public 'id' => int 456
public 'name' => string 'StarCraft: Brood War' (length=20)
public 'slug' => string 'starcraft-brood-war' (length=19)
The fix is pushed to the master repository. Download the update and try it out.
Let me know of the results!
Cheers!
Hi @enisz
The issue with slug was fixed, but now, a new error appears when I use the following search:
$options = array(
'fields' => 'id, slug, cover.url',
'where' => array('rating >= 90', 'cover.url != null'),
'limit' => 48
);
I got Error 400: unknown error
Regards.
Hi @jadersilvabr,
I had to fix a few more issues with the property parsing and also updated the error handling. From now on the query above will produce a proper error message:
Error 400: Syntax Error
In this case you can try to debug the constructed apicalypse string to find out what is the problem with the query. Previously the query string was:
fields id,slug,cover.url;
where rating >= "90" & cover.url != "null";
limit 48;
The problem was that the value 90
was enclosed by quotes. I just pushed a fix to the master, from now on the same query will look like this:
fields id,slug,cover.url;
where rating >= 90 & cover.url != null;
limit 48;
This query is valid, and the results will be in the result array:
array (size=48)
0 =>
object(stdClass)[2]
public 'id' => int 6
public 'cover' =>
object(stdClass)[3]
public 'id' => int 90896
public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co1y4w.jpg' (length=54)
public 'slug' => string 'baldurs-gate-ii-shadows-of-amn' (length=30)
1 =>
object(stdClass)[4]
public 'id' => int 22
public 'cover' =>
object(stdClass)[5]
public 'id' => int 90952
public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co1y6g.jpg' (length=54)
public 'slug' => string 'system-shock-2' (length=14)
...
Please check and verify the changes!
Best Regards
I'm closing this issue as no new issues are reported.
Hello,
I'm try to get data with filter: where slug = 'starcraft-brood-war', but I'm receiving the following error:
Uncaught Exception: Error 400: Expecting a STRING as input, surround your input with quotes starting at 'starcraft' expecting {'{', 'f', '(', '[', 'true', 't', 'false', 'null', 'n'
My code is:
Could you help me?
Regards.