Giter Club home page Giter Club logo

php-riot-api's Introduction

php-riot-api

PHP Wrapper for Riot Games API allows you to quickly make calls to the RIOT API with a proper API Key. Key features include caching (if enabled) and rate limiting. Simply replace API_KEY_HERE with your API key from Riot Games.

Testing.php is a simple testing class that shows how to call all the functions.

Getting Started

  • Replace INSERT_API_KEY_HERE
  • Create folder called 'cache' wherever the script is (make sure it's writeable by php-riot-api)
  • Create an instance of riotapi - $instance = new riotapi($platform);
  • $platform can be na1, euw1, eun1, br1, ru, kr, oc1, la1, la2, jp1, pbe1, tr1 (br/tr only can call getLeague() and getTeam() functions)
  • Make Calls to the functions listed below and receive JSON data
  • Caching is done locally, instantiate php-riot-api with "new riotapi('na1', new FileSystemCache('cache/'));" to create a cache in the subfolder 'cache'
  • DECODE_ENABLED is true by default. If you want your returns to be pure JSON and not an associative array, set it to false
  • Take a look at testing.php for example code, including error handling, caching

Functions

//Returns all champion information.
getChampion();

//Change platform
setRegion($region);

// Returns all free champions.
getChampion(true);
getFreeChampions();

//performs a static call. Not counted in rate limit.
getStatic($call, $id = null, $params = null);

//Returns match details including timeline (if exists) given a match id.
//Use with care, rate limiting is not ready for this function
getMatch($matchId);
//Returns match details given a match id, without timeline.
getMatch($matchId, false);

//Returns timeline of a match
getTimeline($matchId)

//Returns a user's matchList given their account id.
public function getMatchList($accountId,$params=null)

//Returns the league of a given summoner.
getLeague($summoner_id);
getLeaguePosition($summoner_id);

//Returns the challenger ladder.
getChallenger($queue = "RANKED_SOLO_5x5");
//Returns the master ladder.
getMaster($queue = "RANKED_SOLO_5x5");

//returns a summoner's id
getSummonerId($summoner_name);
//returns an account's id
getSummonerAccountId($summoner_name);

//Returns summoner info given summoner id.
getSummoner($summoner_id);
//Returns summoner masteries given summoner id.
getMasteries($summoner_id);
//Returns summoner runes given summoner id.
getRunes($summoner_id);

//Returns summoner info given account id.
getSummoner($accountId);

//Gets a summoner's info given their name, instead of id.
getSummonerByName($summoner_name);

//Return details of an array of matches
//Use with care, rate limiting is not ready for this function
getMatches($ids, $includeTimeline = true)

Not Complete

Region Checking - Some functions are only available in certain regions and not in others.

php-riot-api's People

Contributors

ahubers avatar canisback avatar coltcarder avatar derpthemeus avatar gaetanm avatar kevinohashi avatar playmono avatar primus852 avatar supericy avatar sylven avatar xorinzor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-riot-api's Issues

How to get Solo Queue

Hello
I am using your library for the Riot API and I am completely noob.
The only way I figured to get the League information is that one:
$test->getLeague($summoner_id);

But, I want to isolate the league / division based on the summoner name or ID... I guess there is a way of doing it with the JSON but I have no idea how and the internet couldn't help :(

Can you help me with the code?

Bug const CACHE_LIFETIME_MINUTES

I found a small bug that makes cache unusable.
in php-riot-api.php :

if ($cacheTime > strtotime('-'. CACHE_LIFETIME_MINUTES . ' minutes')) {

should be replace by :

if ($cacheTime > strtotime('-'. self::CACHE_LIFETIME_MINUTES . ' minutes')) {

First run

Error: ACCESS_DENIED
testing cache:Error: ACCESS_DENIED

Newbee question ^^ SplQueue for wamp

Hello there :)

First of all thanks for your helpfull work !

I am not really a pro for the moment ^^ i just would like to know if it's possible to use SplQueue on windows (wamp server) how can i get this class ???
(I am working with Symfony 2)

Thanks a lot in advance !!

Edit : Sorry i solved my problem doing this :

"new \SplQueue();" instead of "new SplQueue();"

Sorry for this issue :s

Best regards,
CUETO Vincent

Special Characters in Summoner Name not working

Using the getSummonerId with summoner names that contain special characters (á,é,î,ô,ý...)
results in NOT FOUND. A fix would be:

$query = "Summoner name with special chars á,é,î,ô,ý" ;
$query = utf8_decode($query) ;

Now you can safely pass your $query to getSummonerId($query):

function getSummonerId($query)
{
    global $api;

    try 
    {
        $r = $api->getSummonerId($sum_name);
        return json2array($r);
    } 
    catch(Exception $e) 
    {
        echo "Error: " . $e->getMessage();
        return null;
    };
}

Inside your php-riot-api.php you have to modify $call inside function getSummonerByName($name):

public function getSummonerByName($name)
{   
    //OLD $call = 'summoner/by-name/' .  rawurlencode($name);
    $call = 'summoner/by-name/' . rawurlencode(utf8_encode($name));

    //add API URL to the call
    $call = self::API_URL_1_4 . $call;

    return $this->request($call);
}

SplQueue not found

When i just copy your library and the example.php to my server, create a cache folder with chmod777 and start your example, it tells me this:

Fatal error: Class 'SplQueue' not found in /home/a8545720/public_html/_/LoLSimpleStats/php-riot-api.php on line 72

Did i make a mistake? How to fix it?

cache

How exactly does the "caching" system work? What is the use of it? How would I use it within my code?

Cache data presented as String and not Array

I apologies firstly as i am quite new to JSON

When i run the following line the first time with DECODE_ENABLED = TRUE;
$getGame = $testCache->getCurrentGame($summoner_id,OC1);
var_dump ($getGame);

It returns an array, but if i go and refresh the page it will return it as a string.

If i do the same thing again with DECODE_ENABLED = FALSE;
it returns a string both times.

Am i missing an option to decode from cache somewhere or am i making a silly mistake?

Having trouble with decodeing arrays from records from tournament codes.

Hello ,
Im trying to make a tournament or a single battle organization site. So far I've succeed creating Tournament Codes , but it seems I have problem with getting the records(reports , stats) from the matches .
Thats the link im trying to figure out , but I just dont understand where did they get the exact information , because it doesn't seems like the one from the API's , it's far more precised(for what i need) . I would be really grateful if you can check the link bellow and offer me some kind of solution.
https://developer.riotgames.com/discussion/riot-games-api/show/Za9fWlET

Thanks , up front !

Problems with certain functions?

I'm having problems with the following functions:
• $r = $test->getSummonerId($summoner_name) - Returns nothing ($r is empty)
• $r = $test->getLeague($summoner_id); - Returns the following:
Array ( [status] => Array ( [message] => Access denied [status_code] => 401 ) )

Is your 'php-riot-api' still working, or since the October 1'st change does it no longer work?

Sorry if these are simple problems to solve but I'm really new to the RIOT API and its the first API with PHP Libraries which just don't seem to work, sigh :(

I've also double checked and my API Key seems to work as other functions to return correct values.

Tournament code report

I'm trying to make my tournament code works.
First I noticed how to hash that code,
But when I put a URL report like
Website.com/report.php
I don't know how to use that page to get the current match detailed
With the report.

Thanks for your help
Shay

Hardcoded CACHE_LIFETIME_MINUTES provides "Phantom Games"

Just noticed that the Hardcoding of the Cache time can be an issue when asking for an Live game, so the cache still shows the game running even tho its finished... for an whole hour...
const CACHE_LIFETIME_MINUTES_LIVE = 5;
And this are the changes to the request Function:

private function request($call, $static = false, $livematch = false)
    {
            if ($this->_responseCode == 200) {
                if ($this->_cache !== null) {
                    if (!$livematch) {
                        $this->_cache->put($url, $result, self::CACHE_LIFETIME_MINUTES * 60);
                    } else {
                        $this->_cache->put($url, $result, self::CACHE_LIFETIME_MINUTES_LIVE * 60);
                        //if the request is a live match, the cache should only last for a few minutes
                        //else a summoner would be shown to be Ingame for another hour even tho he is done.
                    }

                }

Maybe you can find an other more suitable solution but this is how i did it :D and it works just fine.

new function in riot-api

Someone with privilges could add following code:

//Returns the challenger ladder.
public function getChallenger() {
	$call = 'league/challenger?type=RANKED_SOLO_5x5';
	//add API URL to the call
	$call = self::API_URL_2_5 . $call;
	return $this->request($call, true);
}
    //Returns the master ladder.
public function getMaster() {
	$call = 'league/master?type=RANKED_SOLO_5x5';
	//add API URL to the call
	$call = self::API_URL_2_5 . $call;
	return $this->request($call, true);
}

the challenger ladder already exists, but the master ladder was not impl.

getSummonerId() on line 183 (php-riot-api.php)

I ran into this problem while I was testing different names but I'm not sure if it's only me getting this.

Basically your function can't process names with spaces or UTF-8 chars (e.g. The Wild Goat or Ilùvátar or the like) especially because the strtolower() function doesn't work properly with UTF-8 chars. I managed to fix that by replacing strtolower() with mb_strtolower() and adding str_replace():

public function getSummonerId($name) {
            $name = mb_strtolower(str_replace(" ", "",$name), 'UTF-8');
                        (...)
}

Maybe you can find a better solution or arrange it in a better way (I'm still a beginner).

Edit: I checked this #33 but I use double quotes and it doesn't work.

pls help

Hi this isn't so much an issue as me generally needing help with something simple and having nowhere else to turn. I'm trying to access totalSessionsPlayed for each champ and I know in javascript you use resp.champions[0].stats.totalSessionsPlayed but with your functions I just get this huge list of arrays and don't know how to access the specific data as I have not used arrays in php. If you could just help me access totalSessionsPlayed I will be able to understand how to access everything else :)

Calls from API and cache return results in different format

When I make a call with the API, the result looks like

Array ( [summoner_name] => Array ( [id] => summoner_id [name] => summoner_name [profileIconId] => 546 [summonerLevel] => 30 [revisionDate] => 1426288105000 ) ) 

But when I make a call to the local cache, the result looks like

{"summoner_name":{"id":summoner_id,"name":"summoner_name","profileIconId":4,"summonerLevel":30,"revisionDate":1426269306000}}

Can this be made consistent?

caching

I don't think the caching is working because whenever the riot api has a hiccup I'm not getting any data at all, even for summoners I had already searched for.

Fatal error: Uncaught exception 'Exception' with message 'UNAUTHORIZED'

Hello, I have downloaded your API and attempted to execute testing.php on my xxamp and webserver.
I am continuously getting the following error

Fatal error: Uncaught exception 'Exception' with message 'UNAUTHORIZED' in C:\xampp\htdocs\public_html\riotapi\php-riot-api.php:324 Stack trace: #0 C:\xampp\htdocs\public_html\riotapi\php-riot-api.php(154): riotapi->request('https://{region...') #1 C:\xampp\htdocs\public_html\riotapi\testing.php(23): riotapi->getLeague(585897) #2 {main} thrown in C:\xampp\htdocs\public_html\riotapi\php-riot-api.php on line 324

I feel like this is a simple fix and apologize if so, I am trying to learn.
I have checked my PHP version and API key

Caching doesn't work for me

I wanted to rebuilt everything from scratch because i've made changes to the desktop application so i just tried the current php file together with the testings.php

Now it says:

Parse error: syntax error, unexpected '[' in /home/u834577974/public_html/call/FileSystemCache.php on line 69

Is that my fault? did i miss downloading anything etc.?

Can you please help me with an idea how to get the summoner names of players in recent games ?

Hello,
I am building a project, but I'm having difficulties with obtaining all the summoner names in recent games. Getting the summoner ids is easy and clear to me, but I dont have an idea how to get the coresponding summoner names without making numerous requests. Would you please point me in a direction of how to do this, what is the best way, what methods should I use. Thanks in advance :)

bug

// The summoner we are looking for. Lowercase is recommended.
$SUMMONER_NAME = 'Øhm';

example will break with this name...
just saying... need to fix your urlencode

Caching doesnt work for me :(

Hi,
i know you implemented caching, but for me it only works for some functions, not for all of them.
My server requests some data about leages, stats and other stuff about 10 summoners and when
i had only one request to display summoner information, it was all fine and it only made the call once.
But since then i added some requests and my site takes about 30 seconds to load.
(3 requests per summoner * 10)

I took a look at your caching functionality, but i didnt really get why its not working :(

Am i missing something out, or is it rly an api issue?
I guess i did something wrong, but you never know ...

Error Not Found with getMatch & getMatchHistory

Hi !

I just started using your API and tried to test some functions, but I found that getMatch and getMatchHistory give me the error 404 : NOT FOUND :

include('riotapi/php-riot-api.php');
include('riotapi/FileSystemCache.php');

$summoner = htmlspecialchars($_GET["summoner"]);
$region = $_GET["region"];

$api = new riotapi($region);
$cache = new riotapi($region, new FileSystemCache('cache/'));

$sum_id = null;

try {
    $sum_id = $api->getSummonerId($summoner);
} catch(Exception $e) {
    echo "Error: " . $e->getMessage();
}   

$match = $api->getMatchHistory($sum_id);

$sum_id is valid, I can use it with other functions.

Am I doing something wrong ?

Valentin.

Respect Retry-After header

Maybe the api could catch RateLimit exceeded errors and look for the response header Retry-After and reissuing the request if some configuration variable is set. The problem is that with multiple users calling the php files the queue for every single user will not hold enough entries to wait querying.

Caching File

Take a look at the caching code where you set the file path.

The cache file is indicated like this "$cacheFile = 'cache/' . md5($url);" but when you write to the file, you indicate it like a .TXT file, here: "file_put_contents($cacheFile . ".txt", time() . "\n" . $result);". Maybe there is a reason for that, but for me PHP was giving a warning there so i changed and started working. Maybe just define the cacheFile as also .TXT and then remove it from the "file_put_contents" function.

Class SplQueue not found

im using ZendFramework and trying to setup an Little League Page with your api.
sadly im getting this error:
Fatal error: Class 'League\Model\SplQueue' not found in /var/www/html/ZendTest/module/League/src/League/Model/riotapi.php on line 45
(i renamed the file to make it more easy to call)

$this->shortLimitQueue = new SplQueue();-> isent found, he dosent know the class SqlQueue();
i just installed Curl and im running PHP 5.6.21, with Zend Engine v2.6.0 and xdebug v2.4.0 on an CentOS 6.3.

is there any other package i need that i maybe dident see?

Question: How do i get a value from a call?

Hey,

Sorry for being such a noob at this but I'm trying to get the summer id by using the getSummonerByName call.

What i've tried is this "test->getSummonerByName($summoner_name)->id;" and for reasons unknown to me it does not work.

What is the process of getting such information with your wrapper?

Error

Fatal error: Class 'SplQueue' not found in /home/a2714797/public_html/support.php on line 62

Why and how to solve this ?

(support.php is the php-rio-api.php just renamed)

Error Code Handling

Taken from Riot API:
400 Bad request
401 Unauthorized
429 Rate limit exceeded
500 Internal server error
503 Service unavailable

I suppose we could do a function that includes a switch case statement that runs inside each getSomething(); function. For each error code, it would spit out the error and some explanation, and the default case would be to continue, getting your json info.

switch () {
    case error400:
        echo "Bad Request";
        break;
    case error401:
        echo "Unauthorized"
        break;
    case error429: 
        echo "Rate Limit Exceeded";
        break;
    case error500:
        echo "Internal Server Error";
        break;
    case error503:
        echo "Service Unavailable";
        break;
    default:
        //Rest of function.
} 

I've got no clue about how people like to do things in php, this is just the first thing that came to mind.

Refreshing the stats

Hello there,

I am using your library and its been really useful so far. However, when i get stats from riot, it saves to cache (Which is a good thing since it takes up to 10secs and it is one time operation). But it dont refresh unless i clear cache folder manually. And because of that it shows the same stats. Is there any solutions for this ?

Error 429 Rate limit exceeded

Hello again,

I was thinking that the rate limiting was controled by the API with :

LONG_LIMIT_INTERVAL / SHORT_LIMIT_INTERVAL
RATE_LIMIT_LONG / RATE_LIMIT_SHORT

If i exceed the rate limit, the API is not supposed to sleep and request again data when it's possible ?

Thanks in advance !

Best regards,
CUETO Vincent

Notice: Undefined offset: 0 in D:\Web\xampp\htdocs\php-riot-api-master\php-riot-api.php on line 250

Notice: Undefined offset: 0 in D:\Web\xampp\htdocs\php-riot-api-master\php-riot-api.php on line 250

Fatal error: Uncaught exception 'Exception' in D:\Web\xampp\htdocs\php-riot-api-master\php-riot-api.php:250 Stack trace: #0 D:\Web\xampp\htdocs\php-riot-api-master\php-riot-api.php(169): riotapi->request('http://{region}...') #1 D:\Web\xampp\htdocs\php-riot-api-master\php-riot-api.php(133): riotapi->getSummonerByName('voveyla') #2 D:\Web\xampp\htdocs\php-riot-api-master\source.php(28): riotapi->getSummonerId('voveyla') #3 {main} thrown in D:\Web\xampp\htdocs\php-riot-api-master\php-riot-api.php on line 250

Damn error

Can't get division from summonerID

First of all thank you for your great work, it helped me alot.
I'm kind of new to this and have to use an API for a schoolproject but I'm having trouble accessing some data. I already found out how to get summonerID and league tier from the summonername but I can't find out how to get the division.

I hope you have time to help me. If i find out how to get to the division, I'm sure I can find the rest myself.

This is how I tried to get to the division:

$r = $test->getLeague($summID);
$div = $r[$summID][0][0]['division'];
print_r($div);

The second [0] was because the division was inside the first array, not sure if this is the right way

Question about processing the data

Hi there,
First of all, thanks for doing such a good job here. I'm beginner in this stuff but maybe you can help.
I'm working on a project for a small community. So i have summoner id's of everyone in community and i want their league info like "Silver 3", "Bronze 5".
(We are from TR server so my options are limited.)

When i do:
$r = $test->getLeague($summoner_id);
I recieve a huge string. Is there any way to get only data i need?

If not, do you any tips on processing the string to get the data?

Thanks.

Problem...

Hello. im using the php-riot-api-master package 2 months now and it works perfectly... But.. Now i try to make calls and didnt work.. Then. i try to run the new version and return me this message

"Fatal error: Uncaught exception 'Exception' with message 'NO_RESPONSE' in /home/summoner/public_html/test/php-riot-api.php:307 Stack trace: #0 /home/summoner/public_html/test/php-riot-api.php(219): riotapi->request('https//{region}...') #1 /home/summoner/public_html/test/testing.php(14): riotapi->getSummonerByName('RiotSchmick') #2 {main} thrown in /home/summoner/public_html/test/php-riot-api.php on line 307"
this is the message of testing file. I have add the correct api btw..

How to get $matchId

Hi, first thanks for the plugin, it help me really a lot. Now i am trying to get info about the current match of a player. I found the function getMatch but i have to write the matchId. My question is.. how i get the matchid?

3 functions not calling the correct url

Hi I came across a little bug with 3 of your functions:

  • getStatic()
  • getMatch($matchId)
  • getMatchHistory($id)

All these calls will return a 401 because of a problem in the url building. You add an extra / in it while the / is already provided in the API_URL_2_2. An example of this would be:
http://na.api.pvp.net/api/lol/na/v2.2//matchhistory/585897?api_key=
As you can see there is // in front of matchhistory.

The correct functions would be:

public function getStatic($call=null, $id=null) {
        $call = self::API_URL_STATIC_1_2 . $call . $id;

        return $this->request($call, false, true);
    }

public function getMatch($matchId) {
        $call = self::API_URL_2_2  . 'match/' . $matchId;
        return $this->request($call);
    }

public function getMatchHistory($id) {
        $call = self::API_URL_2_2  . 'matchhistory/' . $id;
        return $this->request($call);
    }

Regards
Kevin

error 500 when searching for a non-existent summoner

Thanks again for your work,

I've run into some trouble again. Whenever i try to search the summonerID from a non-existent summoner name, the request reaches a error 500 page.

The problem now is that I can't get rid of this error. I tried error handling already (try catch and a normal if statement) but it doesn't work because nothing is stored inside the variable i want to store the ID in.

This part of code is where it all goes wrong

// summonerName -> summonerID
$summID = $test->getSummonerId($summName);
$_SESSION['summonerID'] = $summID;

I got this error when i enabled display errors:

Fatal error: Uncaught exception 'Exception' with message 'NOT_FOUND' in /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php:325 Stack trace: #0 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php(237): riotapi->request('https://{region...') #1 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php(194): riotapi->getSummonerByName('nzczjdscjkckj') #2 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/getData.php(20): riotapi->getSummonerId('nzczjdscjkckj') #3 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/login.php(43): include('/home/i313451/d...') #4 {main} thrown in /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php on line 325

I hope you get more out of it then I did.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.