Converting RiotGames JSON API to PHP

349
April 01, 2017, at 05:57 AM

I'm having an issue retrieving certain information from RiotGames API. The code shown below is me retrieving the wins and losses for game types (if available).

<?php   
    // get that summoner's wins and losses for each game type
    $result = file_get_contents('https://na.api.pvp.net/api/lol/na/v1.3/stats/by-summoner/' . $summoner->id . '/summary?api_key=' . $apiKey);
    $stats = json_decode($result);
    // var_dump($stats);
    foreach($stats->playerStatSummaries as $statSummary){
        // $statSummary->losses: sometimes losses isn't set
        $losses = property_exists($statSummary, 'losses')? $statSummary->losses : '(not available)';
        print '<p><b>' . $statSummary->playerStatSummaryType . '</b>: ' .
                $statSummary->wins . ' wins, ' . $losses . ' losses</p>';
    }
?>

It fetches the wins and losses of Riot's API and returns it. But if I try to grab something different such as totalAssists from their aggregatedStats and replace wins with totalAssists it will return false with this error

"type 8 -- Undefined property: stdClass::$totalAssists -- at line 35"

Why does this not work? (You can find all the information of RiotsAPI by clicking here and then clicking the second "GET" under "STATS-V1.3"

Answer 1

Is it possible that the total assists doesn't exist also? Can you share the JSON object?

You said if you "replace wins with totalAssists" that you get an error. Are you aware that you're not checking to see if wins exists too?

Are you replacing it with "totalAssists" or "$aggregatedStats->totalAssists"?

Rent Charter Buses Company
READ ALSO
Why my this mysqli returning an error

Why my this mysqli returning an error

Today my site stop working maybe because I am using MySQL then I update my script to mysqli, but it gives error and I am not able to find the way that how to solve or fix this problem

281
When creating a nerd in my nerd_table I get the following error

When creating a nerd in my nerd_table I get the following error

This is my code from create_users_tablephp

312
Pulling Random Image From Directory with PHP

Pulling Random Image From Directory with PHP

I'm trying to produce a random image on my 404 pages from a directory in my assetsI found another thread using the code I'm using, but I have had zero luck getting this to work

358
Laravel - how to know if the attribute exists in relacional table

Laravel - how to know if the attribute exists in relacional table

im doing a property sales website, and i have todo an advanced search, with number of bedroom for example

320