#1 Posted by tjockapa (2 posts) -

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?

#2 Posted by Avenged (27 posts) -

  
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 

#3 Posted by LordAndrew (14426 posts) -
@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 );