enisz / igdb

IGDB PHP API Wrapper
GNU General Public License v3.0
27 stars 8 forks source link

More fields in Game endpoint #26

Closed games-geeks closed 1 year ago

games-geeks commented 1 year ago

Hello, I'm using this api, it's good. But it misses some field such language for a game

Can you add it?

Thanks

enisz commented 1 year ago

Hi @games-geeks,

I can see there are a lot of new endpoints since the last update of this wrapper. I may update it in the future, however there may be a workaround for your problem. The fields are not limited by the wrapper, only the endpoints are checked. Check out this example:

<?php
    $igdb = new IGDB($client_id, $access_token);
    $builder = new IGDBQueryBuilder();
    $builder
        ->id(7331)
        ->fields('id,name,language_supports');
    $query = $builder->build();

    try {
        var_dump($igdb->game($query));
    } catch (Exception $e) {
        echo $e->getMessage();
    }
?>

This query will result in the response below

array (size=1)
  0 => 
    object(stdClass)[3]
      public 'id' => int 7331
      public 'name' => string 'Uncharted 4: A Thief's End' (length=26)
      public 'language_supports' => 
        array (size=8)
          0 => int 211197
          1 => int 211200
          2 => int 211204
          3 => int 211205
          4 => int 211207
          5 => int 211210
          6 => int 211212
          7 => int 211213

You can collect the related language data with the expander feature like this:

<?php
    $igdb = new IGDB($client_id, $access_token);
    $builder = new IGDBQueryBuilder();
    $builder
        ->id(7331)
        ->fields('id,name,language_supports.language.name,language_supports.language.native_name,language_supports.language.locale');
    $query = $builder->build();

    try {
        var_dump($igdb->game($query));
    } catch (Exception $e) {
        echo $e->getMessage();
    }
?>

This query will show you the languages realted to the game you are looking for

array (size=1)
  0 => 
    object(stdClass)[3]
      public 'id' => int 7331
      public 'name' => string 'Uncharted 4: A Thief's End' (length=26)
      public 'language_supports' => 
        array (size=8)
          0 => 
            object(stdClass)[4]
              public 'id' => int 211197
              public 'language' => 
                object(stdClass)[5]
                  public 'id' => int 7
                  public 'name' => string 'English' (length=7)
                  public 'native_name' => string 'English (US)' (length=12)
                  public 'locale' => string 'en-US' (length=5)
          1 => 
            object(stdClass)[6]
              public 'id' => int 211200
              public 'language' => 
                object(stdClass)[7]
                  public 'id' => int 12
                  public 'name' => string 'French' (length=6)
                  public 'native_name' => string 'Français' (length=9)
                  public 'locale' => string 'fr-FR' (length=5)
          2 => 
            object(stdClass)[8]
              public 'id' => int 211204
              public 'language' => 
                object(stdClass)[9]
                  public 'id' => int 21
                  public 'name' => string 'Portuguese (Brazil)' (length=19)
                  public 'native_name' => string 'Português (Brasil)' (length=19)
                  public 'locale' => string 'pt-BR' (length=5)
          3 => 
            object(stdClass)[10]
              public 'id' => int 211205
              public 'language' => 
                object(stdClass)[11]
                  public 'id' => int 10
                  public 'name' => string 'Spanish (Mexico)' (length=16)
                  public 'native_name' => string 'Español (Mexico)' (length=17)
                  public 'locale' => string 'es-MX' (length=5)
          4 => 
            object(stdClass)[12]
              public 'id' => int 211207
              public 'language' => 
                object(stdClass)[13]
                  public 'id' => int 7
                  public 'name' => string 'English' (length=7)
                  public 'native_name' => string 'English (US)' (length=12)
                  public 'locale' => string 'en-US' (length=5)
          5 => 
            object(stdClass)[14]
              public 'id' => int 211210
              public 'language' => 
                object(stdClass)[15]
                  public 'id' => int 12
                  public 'name' => string 'French' (length=6)
                  public 'native_name' => string 'Français' (length=9)
                  public 'locale' => string 'fr-FR' (length=5)
          6 => 
            object(stdClass)[16]
              public 'id' => int 211212
              public 'language' => 
                object(stdClass)[17]
                  public 'id' => int 21
                  public 'name' => string 'Portuguese (Brazil)' (length=19)
                  public 'native_name' => string 'Português (Brasil)' (length=19)
                  public 'locale' => string 'pt-BR' (length=5)
          7 => 
            object(stdClass)[18]
              public 'id' => int 211213
              public 'language' => 
                object(stdClass)[19]
                  public 'id' => int 10
                  public 'name' => string 'Spanish (Mexico)' (length=16)
                  public 'native_name' => string 'Español (Mexico)' (length=17)
                  public 'locale' => string 'es-MX' (length=5)

Hopefully this will work for you until I update the wrapper.

enisz commented 1 year ago

Just did an update, merged it to master. Give it a try!

Feel free to reopen the issue if you face any problems.

games-geeks commented 1 year ago

Thanks for your replies. I can use it, and in fact it's pretty easy to add an endpoint! Thnaks a lot