BenFradet / RiotSharp

C# wrapper for the Riot Games API
http://benfradet.github.io/RiotSharp/
MIT License
301 stars 145 forks source link

Looking for any C# code examples of basic use of the wrapper, like for getting match history and match headers from Summoner Name? #608

Open itorres008 opened 5 years ago

itorres008 commented 5 years ago

The short: Are there any VB or C# code examples of basic use of the wrapper, like entering a Summoner Name and getting match history and match headers? At least to the level shown in Riot’s Summoner Match History page.

I asked Ben and he replied "I would log an issue in the repo, I'm sure there are users that could give you such an example." So, here I'am.

Objective: I’m looking to get match data history for a Summoner to show statistics about win/loss, KDA. CS, Damage/min, total and by Champion. It’s basic stuff.

About Me: I have years of experience in Info Systems but learned procedural programming and relational databases before object oriented programming was a thing. 😊 I have worked some with Visual Basic, but I’m rusty on it and C# is the thing now and I doubt there will be code examples in VB, although I'd prefer it. So, I’ll be fresh tackling C# syntax and JSON data manipulation. In my experience, I feel a most useful tool is to have a working project source code to examine and learn from.

So, I wonder if there are any code examples out there which may show the usage of RiotSharp towards the objective I described.

Thanks for the help.

JanOuborny commented 5 years ago

Here is a quick example code:

var riotApi = RiotApi.GetDevelopmentInstance("YOUR_API_KEY");

// Get the account information of your preferred summoner by its name
var summonerName = "imaqtpie";
var summoner = riotApi.Summoner.GetSummonerByNameAsync(RiotSharp.Misc.Region.na, summonerName).Result;

// Get a list of the last 100 games. More infos about getting more games here: https://developer.riotgames.com/api-methods/#match-v4/GET_getMatchlist
var matchListOfSummoner = riotApi.Match.GetMatchListAsync(RiotSharp.Misc.Region.na, summoner.AccountId).Result;

// List contains only references to matches, therefore you have to get the match data for each match seperately.
foreach (var matchReference in matchListOfSummoner.Matches)
{
    var match = riotApi.Match.GetMatchAsync(RiotSharp.Misc.Region.na, matchReference.GameId).Result;

    // Get participant stats object of summoner (imaqtpie)
    var particpantsId = match.ParticipantIdentities.Single(x => x.Player.AccountId == summoner.AccountId);
    var participantsStats = match.Participants.Single(x => x.ParticipantId == particpantsId.ParticipantId);

    // Do stuff with stats
}

This example uses LINQ. Therefore, you have to add this import statement to the beginning of your class: using System.Linq;

RiotSharp is written for asynchronous usage. For the sake of simplicity I'm forcing the methods into synchronous execution by using .Result after each asyncronous method.

BenFradet commented 5 years ago

It'd be great to renovate the readme examples :+1:

itorres008 commented 5 years ago

Jan, I haven't had the chance to work with this yet, but wanted to at least let you know I've seen the sample code and thank you for the help. I'll report back.

Ben, Thank you, too,

WeTheNinjas commented 2 years ago

Hello, I know it's been a very long time, sorry. I am having problems receiving the "matchListOfSummoner ", it returns 'results = null' and it throws an exception saying "RiotSharpException: Bad request - Invalid routing value eun1". The only lines of code I have are the first four lines you posted above (except the region is .Eune). has the API changed or smthing?

Thanks in advance. duppah

xXLAOKOONXx commented 2 years ago

Match API listens to areas, so try Europe as Region value

itorres008 commented 2 years ago

"The only lines of code I have are the first four lines you posted above (except the region is .Eune). has the API changed or smthing?" Yes, after changing from MATCH-V4 to MATCH-V5 the RiotSharp.Misc.Region codes (or ENUM values) changed from Na, Euw, Eune.... to Americas, Europe, etc So, if you wanted Eune... var match = riotApi.Match.GetMatchAsync(RiotSharp.Misc.Region.Americas, matchReference).Result;

I haven't done much, but I ran into this one. So, I had to share. :-)

WeTheNinjas commented 2 years ago

"The only lines of code I have are the first four lines you posted above (except the region is .Eune). has the API changed or smthing?" Yes, after changing from MATCH-V4 to MATCH-V5 the RiotSharp.Misc.Region codes (or ENUM values) changed from Na, Euw, Eune.... to Americas, Europe, etc So, if you wanted Eune... var match = riotApi.Match.GetMatchAsync(RiotSharp.Misc.Region.Americas, matchReference).Result;

I haven't done much, but I ran into this one. So, I had to share. :-)


Thank you for the reply, Tested and worked. Unfortunately tho what I have been trying to do is get the custom matches of my friends for fun analysis type of thing but after a few searches I saw that custom matches are private and theres no way getting them through the API which is a real bummer. Thank you so much for the help tho 😊

itorres008 commented 2 years ago

I see... I found this talking about future plans to allow players to authorize retrieving their own custom game data. So, maybe there's still hope.

"Custom Data • Currently, custom game data (excluding the tournament system), is not retrievable from the API due to privacy policies. Riot is slowly but surely working towards an external RSO (Riot Sign-On) solution that will allow individual players to “Okay” websites to use their custom game data. Verification RSO is Riot Sign-On, the login logic you see whenever you access anything that requires your Riot account. RSO is not yet ready for the public to use, but Riot has implemented a work-around for websites to verify users. Websites should generate a random string for the user to input into their client. See this gif for an illustration. The verification endpoint is notorious for having issues. The user may need to restart their client a few times to get it working, or try again later."

From https://riot-api-libraries.readthedocs.io/en/latest/specifics.html

What I want to do is similar, retrieve my data and have stats for performance on distinct champions/lane.

WeTheNinjas commented 2 years ago

Thank you so much for the reply I appreciate it so much! I will keep an eye out, and thank you so much for that source. Highly appreciated!!