1. Go to this page and download the library: Download kronusme/dota2-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/ */
kronusme / dota2-api example snippets
use Dota2Api\Api;
Api::init('YOUR_API_KEY', array('localhost', 'root', 'password', 'db_name', 'table_prefix_'));
$mm = new Dota2Api\Mappers\MatchMapperWeb(121995119);
$match = $mm->load();
$mm = new Dota2Api\Mappers\MatchMapperWeb(121995119);
$match = $mm->load();
$saver = new Dota2Api\Mappers\MatchMapperDb();
$saver->save($match);
$leaguesMapperWeb = new Dota2Api\Mappers\LeaguesMapperWeb();
$leagues = $leaguesMapperWeb->load();
foreach($leagues as $league) {
echo $league->get('description');
if ($league->get('tournament_url')) {
echo $league->get('tournament_url');
}
}
$leaguePrizePoolMapperWeb = new Dota2Api\Mappers\LeaguePrizePoolMapperWeb();
$leaguePrizePoolMapperWeb->setLeagueId(600);
$prizePoolInfo = $leaguePrizePoolMapperWeb->load();
print_r($prizePoolInfo);
echo $prizePoolInfo['prize_pool'];
echo $prizePoolInfo['league_id'];
echo $prizePoolInfo['status']; // may be undefined
$prizePoolMapperDb = new Dota2Api\Mappers\LeaguePrizePoolMapperDb();
$pp = $prizePoolMapperDb->setLeagueId(600)->load();
foreach($pp as $date=>$prize_pool) {
echo $date.' - $ '.number_format($prize_pool, 2);
}
$leagueMapper = new Dota2Api\Mappers\LeagueMapper(22); // set league id (can be get via leagues_mapper)
$games = $leagueMapper->load();
print_r($games);
$matchesMapperDb = new Dota2Api\Mappers\MatchesMapperDb();
$matchesMapperDb->setLeagueId(29)->setMatchesRequested(1);
$matchesInfo = $matchesMapperDb->load();
print_r($matchesInfo);
$matchesMapperDb = new Dota2Api\Mappers\MatchesMapperDb();
$matchesMapperDb->delete(array(151341579, 151401247));
$mm = new Dota2Api\Mappers\MatchMapperDb();
$mm->delete(151341579);
$abilities = new Dota2Api\Data\Abilities();
$abilities->parse();
$abilities->getDataById(5172); // return array for ability with id 5172 (BeastMaster Inner Beast)
// same, because there are no thumbs for abilities
$abilities->getImgUrlById(5172, false);
$abilities->getImgUrlById(5172);
$heroes = new Dota2Api\Data\Heroes();
$heroes->parse();
$heroes->getDataById(97); // get info about Magnus
$heroes->getImgUrlById(97, false); // large image
$heroes->getImgUrlById(97); // thumb
$items = new Dota2Api\Data\Items();
$items->parse();
$items->getDataById(149); // get info about Crystalis
$items->getImgUrlById(149, false); // large image
$items->getImgUrlById(149); // thumb
$mods = new Dota2Api\Data\Mods();
$mods->parse();
$mods->getFieldById(1, 'name'); // returns 'All Pick'
$lobbies = new Dota2Api\Data\Lobbies();
$lobbies->parse();
$lobbies->getFieldById(2, 'name'); // returns 'Tournament'
$regions = new Dota2Api\Data\Regions();
$regions->parse();
$regions->getFieldById(132, 'name'); // returns 'Europe West'
$playersMapperDb = new Dota2Api\Mappers\PlayersMapperDb();
$players_info = $playersMapperDb->addId('76561198020176880')->addId('76561197998200662')->load();
print_r($players_info);
$playerMapperDb = new Dota2Api\Mappers\PlayerMapperDb();
$playerMapperDb->setSteamid('76561198020176880');
print_r($playerMapperDb->load());
//fetch players from API
$playersMapperWeb = new Dota2Api\Mappers\PlayersMapperWeb();
$players = $playersMapperWeb->addId('76561198020176880')->addId('76561197998200662')->load();
//save players into db
$playerMapperDb = new Dota2Api\Mappers\PlayerMapperDb();
foreach($players as $p) {
$playerMapperDb->save($p);
}
$matchMapperWeb = new Dota2Api\Mappers\MatchMapperWeb(37633163);
$game = $matchMapperWeb->load();
$ugcMapperWeb = new Dota2Api\Mappers\UgcMapperWeb($game->get('radiant_logo'));
$logoData = $ugcMapperWeb->load();
var_dump($logoData);
echo $logoData->url;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.