1. Go to this page and download the library: Download giantbomb/giantbomb-php-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
giantbomb / giantbomb-php-api example snippets
use \GiantBomb\Client\GiantBombClient;
$config = array(
'apiKey' => 'your-api-key',
'cache' => array(
'type' => 'redis', // Or memcached
'servers' => array( array( 'host' => 'localhost', 'port' => 6397, 'timeout' => 0 ) ), // weight is also a parameter for memcached
'persistent' => true
)
);
/**
Memcached also has the "options" parameter for specifiying Memcached options (via constants)
Redis also has the "password" parameter for auth, and "dbindex" for specifying your db
*/
$client = GiantBombClient::factory( $config );
$requestArgs = array(
'limit' => 100, // Max of 100,
'offset' => 0, // Default is 0
// 'field_list' => 'name', // Default is not set
// 'sort' => 'name|asc', // Default is not set
// 'filter' => 'name:portal 2', // Default is not set
);
// Depending on the query, there are different options afailable. Check out the [service description][3] for more information.
$response = $client->getGames( $requestArgs );
if( $response->getStatusCode() === 1 ) {
printf( "There are %d total results. Currently showing %d, starting at %d.\n<br /><br />", $response->getNumberOfTotalResults(), $response->getNumberOfPageResults(), $response->getOffset() );
$games = $response->getResults();
// HUGE dump. Careful
//var_dump( $games );
// Get more info on a single game
$game = $games->get( 0 )->getDetail()->getResults();
// All functions are magic functions based on the camel case of the key from the API result. This goes for anything returned from the API
printf( "Game: %s<br />", $game->getName() );
} else {
printf( "There was an error: %s", $response->getError() );
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.