1. Go to this page and download the library: Download kris-kuiper/igdbv4 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/ */
kris-kuiper / igdbv4 example snippets
use KrisKuiper\IGDBV4\Authentication\AuthConfig;
use KrisKuiper\IGDBV4\Authentication\Authentication;
use GuzzleHttp\Client;
$config = new AuthConfig('your client id', 'your secret');
$client = new Client();
$authentication = new Authentication($client, $config);
$token = $authentication->obtainToken();
//The token will hold all the information you need to create a request to the IGDB API
$token->getAccessToken();
$token->getExpiration(); //The amount of seconds this token is valid
use GuzzleHttp\Client;
use KrisKuiper\IGDBV4\IGDB;
use KrisKuiper\IGDBV4\Authentication\ValueObjects\AccessConfig;
$client = new Client();
$config = new AccessConfig('your client id', 'your access token');
$igdb = new IGDB($client, $config);
//Games
$igdb->game()->findById(375); //Find a game by id with optional selecting fields
$igdb->game()->findById(375, ['name', 'storyline', 'platforms.*']); //Find a game by id and specifying the fields to return
$igdb->game()->search('Metal Gear Solid'); //Search games by title
$igdb->game()->search('Metal Gear Solid', ['name', 'storyline', 'platforms.*']); //Search games by title and specifying the fields to return
$igdb->game()->list(); //List all games (limit will be 500 as default)
$igdb->game()->list(50, 20); //Setting an offset and limit (for pagination purposes)
$igdb->game()->query('fields name, storyline, platforms.*; where platforms = (7,9); sort id asc; limit 50'); //Using a custom query (see the Advanced Query builder section for creating queries programmatically)
//Platforms
$igdb->platform()->findById(5, ['name', 'slug']);
$igdb->platform()->list();
$igdb->platform()->search('Playstation');
$igdb->platform()->query('fields name, slug; limit 500; sort id;');
//Genres
$igdb->genre()->findById(5, ['name', 'slug']);
$igdb->genre()->list();
$igdb->genre()->query('fields name, slug; limit 500; sort id;');
use GuzzleHttp\Client;
use KrisKuiper\IGDBV4\IGDB;
use KrisKuiper\IGDBV4\Authentication\ValueObjects\AccessConfig;
use KrisKuiper\IGDBV4\QueryBuilder\Query;
$client = new Client();
$config = new AccessConfig('your client id', 'your access token');
$igdb = new IGDB($client, $config);
//fields name, storyline, platforms.*; where platforms = (7, 9) & genre != 45; sort id asc; limit 20;
$query = (new Query())
->fields('name', 'storyline', 'platforms.*')
->where('platforms', [7, 9])
->where('genre', 45, '!=')
->sort('id')
->limit(20)
->build();
$igdb->game()->query($query);
use KrisKuiper\IGDBV4\QueryBuilder\Query;
//fields name, storyline; platforms.*; where id = 375;
$query = (new Query())
->fields('name', 'storyline', 'platforms.*')
->where('id', 375)
->build();
//fields name, storyline; search "Metal Gear Solid; limit 50;
$query = (new Query())
->fields('name', 'storyline', 'platforms.*')
->search('Metal Gear Solid')
->limit(50)
->build();
//fields *; exclude genre, platforms, keywords; sort name desc; limit 50;
$query = (new Query())
->fields('*')
->exclude('genre', 'platform', 'keywords')
->limit(50)
->sort('name', 'desc')
->build();