Find cover-url for game

Avatar image for tjockapa
tjockapa

18

Forum Posts

1

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#1  Edited By tjockapa

Im trying to find the cover-url for images with php (eg. Wave Race 64)
Could I get some help with the code for this? Anyone with an example?

Avatar image for avenged
avenged

43

Forum Posts

282

Wiki Points

0

Followers

Reviews: 0

User Lists: 3

#2  Edited By avenged

  
You need to send a URL request by either searching the game by title or by sending a request for a particular game. Normally a good starting point is to use the Search resource, then if you need more information send another request to the Game resource.
  
Search resource:
http://api.giantbomb.com/search/?api_key=API_KEY&query=wave%20race%2064&field_list=name,image&format=json     
 
 Game resource: 
http://api.giantbomb.com/game/11969/?api_key=API_KEYc&field_list=name,image&format=json  
 
You will then get back a collection of URLs containing images (varying sizes) that should be used for the games main cover image.  
 
In order to send a URL request in php I believe you need to send a GET request using $_GET 

Avatar image for lordandrew
LordAndrew

14609

Forum Posts

98305

Wiki Points

0

Followers

Reviews: 0

User Lists: 36

#3  Edited By LordAndrew
@Avenged: $_GET is a superglobal. It doesn't actually do anything.
 
@tjockapa: PHP provides several functions that you can use to download web pages. There's file_get_contents, fopen, cURL, and probably more. Read up on them and pick which one you like best, but cURL is supposed to be the fastest of that group. And then PHP also has functions for parsing XML and JSON, so you can extract the data you want from the results. 
 
Here's a snippet from one of my own projects. The URL has already been built, and it's stored in a variable called $apiString for some reason.

    // Use cURL if possible
    if ( function_exists( 'curl_init' ) ) {
        $ch = curl_init( $apiString );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent );
        $apiResults = curl_exec( $ch );
        curl_close( $ch );
    } else {
        $apiResults = file_get_contents( $apiString );
    }
    $apiResultsArray = json_decode( $apiResults );