0

I have been using my Riot Api to check current division of given summoner, but probably after an update it stopped working, here is my code:

<?php

namespace AppBundle\Utils;

class LolApi
{

    private $apiKey = 'my api key';

    private $server = 'eun1';

    public static function makeRequest($url)
    {
        $result = file_get_contents($url);
        sleep(1.5);

        return $result;
    }

    private function executeCommand($command)
    {
        try {
            $url =
            $c = file_get_contents('https://' . $this->server . '.api.riotgames.com' . $command . '?api_key=' . $this->apiKey);

            return json_decode($c);
        } catch (Exception $e) {
            return null;
        }
    }

    public function setServer($server)
    {
        if ($server == 'EUNE') {
            $this->$server = 'eun1';
        }
        if ($server == 'EUW') {
            $this->$server = 'euw1';
        }
        if ($server == 'NA') {
            $this->$server = 'na1';
        }
        if ($server == 'OCE') {
            $this->$server = 'oc1';
        }
    }

    public function getSummonerIdByName($summonerName)
    {
        $data = $this->executeCommand('/lol/summoner/v3/summoners/by-name/' . rawurlencode($summonerName));

        return $data->id;
    }

    public function getAccountIdByName($summonerName)
    {
        $data = $this->executeCommand('/lol/summoner/v3/summoners/by-name/' . rawurlencode($summonerName));

        return $data->accountId;
    }

    public function getDivision($summonerName)
    {
        $id = $this->getSummonerIdByName($summonerName);

        $data = $this->executeCommand('/lol/league/v3/positions/by-summoner/' . $id);

        foreach ($data as $entry) {
            if ($entry->queueType == 'RANKED_SOLO_5x5') {
                return [$entry->tier, $entry->rank];
            }
        }

//        dump($id); exit;

        return [null, null];
    }


    public function getSpectateMatch($summonerName)
    {
        $id = $this->getSummonerIdByName($summonerName);
        $data = null;
        try {
            $data = $this->executeCommand('/lol/spectator/v3/active-games/by-summoner/' . $id);
        } catch (\Exception $e) {

        }

        return $data;
    }

    public function getMatches($summonerName)
    {
        $id = $this->getAccountIdByName($summonerName);
        $data = $this->executeCommand('/lol/match/v3/matchlists/by-account/' . $id . '/recent');

        $matchIds = [];

        foreach ($data->matches as $match) {
            array_push($matchIds, $match->gameId);
        }

        $retString = '';
        $matchList = [];

        foreach ($matchIds as $matchId) {
            $data = $this->executeCommand('/lol/match/v3/matches/' . $matchId);
            $continueMatchProcessing = true;

            foreach ($data->participantIdentities as $participantIdentity) {
                if (!isset($participantIdentity->player)) {
                    $continueMatchProcessing = false;
                    break;
                }

                if ($participantIdentity->player->summonerName == $summonerName) {
                    $playerParticipantId = $participantIdentity->participantId;
                }
            }

            if (!$continueMatchProcessing) {
                continue;
            }


            foreach ($data->participants as $participant) {
                if ($participant->participantId == $playerParticipantId) {
                    $matchArray = [
                        $participant->stats->win,
                        $participant->stats->kills,
                        $participant->stats->deaths,
                        $participant->stats->assists,
                        $participant->stats->goldEarned,
                        $participant->stats->totalMinionsKilled,
                        $participant->stats->item0,
                        $participant->stats->item1,
                        $participant->stats->item2,
                        $participant->stats->item3,
                        $participant->stats->item4,
                        $participant->stats->item5,
                        $participant->stats->item6,
                        $participant->spell1Id,
                        $participant->spell2Id,
                        $participant->championId,
                        $data->gameDuration
                    ];

                    array_push($matchList, $matchArray);
                }
            }
        }

        return $matchList;
    }
}

?>

I swapped v3 to v4 but it did not help. I am new to php, just editing my current code.

Also adding a screenshot of my API dev panel, and the error Get message:

screenshot

The code is supposed to get the summoner name from Riot servers and check for current league, division, recent match history.

edo
  • 41
  • 6

1 Answers1

1

Riot Games removed some of the v3 API endpoints and now moved to v4, you can find the new version endpoints here and as for the data dragon version, you can find it here

Example: /lol/summoner/v4/summoners/by-name/{summonerName}

They are also now using encrypted ids now and added another identifier for summoner called puuid

You can join their discord here

KowaiiNeko
  • 327
  • 6
  • 17
  • I updated v3 to v4, although I have no idea how to get recent matches -> public function getMatches($summonerName) Is there any chance you could help me with that since my knowledge is 'basic' – edo Mar 26 '19 at 07:53
  • There are parameters that you can use for that. `https://na1.api.riotgames.com/lol/match/v4/matchlists/by-account/ACCOUNT_ID?endIndex=ENDINT_INDEX&beginIndex=STARTING_INDEX&api_key=API_KEY`. `beginIndex` is the last game summoner played while `endIndex` is the last ending match – KowaiiNeko Mar 26 '19 at 16:23