Code Monkey home page Code Monkey logo

Comments (3)

enisz avatar enisz commented on August 24, 2024 1

Hi,

Sorry, I saw your last comment just forgot to answer it. The issue you linked was related of an earlier version of the IGDB api where the cover was an object. Since then it got changed.

Thanks for closing the issue!

from igdb.

enisz avatar enisz commented on August 24, 2024

Hi @RazenIW,

Thank you for using my wrapper! I just checked the examples I made eariler and I cannot find any with the cover field being an object. Can you tell me where did you see this? Or where this example is located? It is possible that it worked different on earlier versions of IGDB API and I forgot to update the documentation somewhere.

Currently the API will return a cover id in this field. If you check the game endpoint documentation you can see that the cover field is a reference id for a cover object. In this case you can either:

  • send another query to the cover endpoint with the ID you got
  • use the expander feature of the IGDB API

I recommend using the expander. This way you can get every information you want in a single query. To use the expander update your options array as below:

$options = array(
    'search' => 'uncharted 4',
    'fields' => array(
        'id',
        'name',
        'cover.*' // note the expander feature here
    )
);

Using these options the return value of the query changes as below:

array (size=5)
  0 => 
    object(stdClass)[2]
      public 'id' => int 7331
      public 'cover' => 
        object(stdClass)[3]
          public 'id' => int 81917
          public 'alpha_channel' => boolean false
          public 'animated' => boolean false
          public 'game' => int 7331
          public 'height' => int 960
          public 'image_id' => string 'co1r7h' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co1r7h.jpg' (length=54)
          public 'width' => int 720
          public 'checksum' => string 'd2893576-b1fe-06e2-c813-2896e1bba9a1' (length=36)
      public 'name' => string 'Uncharted 4: A Thief's End' (length=26)
  1 => 
    object(stdClass)[4]
      public 'id' => int 136686
      public 'name' => string 'Uncharted 4: A Thief's End - Deluxe Edition' (length=43)
  2 => 
    object(stdClass)[5]
      public 'id' => int 41874
      public 'cover' => 
        object(stdClass)[6]
          public 'id' => int 100142
          public 'alpha_channel' => boolean false
          public 'animated' => boolean false
          public 'game' => int 41874
          public 'height' => int 993
          public 'image_id' => string 'co259q' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co259q.jpg' (length=54)
          public 'width' => int 744
          public 'checksum' => string '7f899c70-4c8a-fc64-0901-74d01d32638a' (length=36)
      public 'name' => string 'Uncharted 4: A Thief's End Special Edition' (length=42)
  3 => 
    object(stdClass)[7]
      public 'id' => int 41879
      public 'cover' => 
        object(stdClass)[8]
          public 'id' => int 110424
          public 'alpha_channel' => boolean false
          public 'animated' => boolean false
          public 'game' => int 41879
          public 'height' => int 1687
          public 'image_id' => string 'co2d7c' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co2d7c.jpg' (length=54)
          public 'width' => int 1265
          public 'checksum' => string 'bebab7e4-a94d-7ff5-3fc3-ea16e1a3ed2f' (length=36)
      public 'name' => string 'Uncharted 4: A Thief's End Libertalia Collector's Edition' (length=57)
  4 => 
    object(stdClass)[9]
      public 'id' => int 112090
      public 'cover' => 
        object(stdClass)[10]
          public 'id' => int 69356
          public 'alpha_channel' => boolean false
          public 'animated' => boolean false
          public 'game' => int 112090
          public 'height' => int 444
          public 'image_id' => string 'co1hik' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co1hik.jpg' (length=54)
          public 'width' => int 492
          public 'checksum' => string '15be2383-507c-becd-a6ab-d02ecccfa3f1' (length=36)
      public 'name' => string 'Uncharted Water IV' (length=18)

The cover object in the results will contain all fields of the cover endpoint. Of course, you can fine tune this by using specific fields to exclude unnecessary information.

$options = array(
    'search' => 'uncharted 4',
    'fields' => array(
        'id',
        'name',
        'cover.image_id', // view the image_id
        'cover.url'       // and url fields only
    )
);

The result will be:

array (size=5)
  0 => 
    object(stdClass)[2]
      public 'id' => int 7331
      public 'cover' => 
        object(stdClass)[3]
          public 'id' => int 81917
          public 'image_id' => string 'co1r7h' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co1r7h.jpg' (length=54)
      public 'name' => string 'Uncharted 4: A Thief's End' (length=26)
  1 => 
    object(stdClass)[4]
      public 'id' => int 136686
      public 'name' => string 'Uncharted 4: A Thief's End - Deluxe Edition' (length=43)
  2 => 
    object(stdClass)[5]
      public 'id' => int 41874
      public 'cover' => 
        object(stdClass)[6]
          public 'id' => int 100142
          public 'image_id' => string 'co259q' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co259q.jpg' (length=54)
      public 'name' => string 'Uncharted 4: A Thief's End Special Edition' (length=42)
  3 => 
    object(stdClass)[7]
      public 'id' => int 41879
      public 'cover' => 
        object(stdClass)[8]
          public 'id' => int 110424
          public 'image_id' => string 'co2d7c' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co2d7c.jpg' (length=54)
      public 'name' => string 'Uncharted 4: A Thief's End Libertalia Collector's Edition' (length=57)
  4 => 
    object(stdClass)[9]
      public 'id' => int 112090
      public 'cover' => 
        object(stdClass)[10]
          public 'id' => int 69356
          public 'image_id' => string 'co1hik' (length=6)
          public 'url' => string '//images.igdb.com/igdb/image/upload/t_thumb/co1hik.jpg' (length=54)
      public 'name' => string 'Uncharted Water IV' (length=18)

Hope this helps!

from igdb.

RazenIW avatar RazenIW commented on August 24, 2024

Hello,

I tried using the expander feature and it works now 👍
This is where I saw cover fields being objects instead of integers at first.

Thanks a lot !

from igdb.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.