Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question League of Legends API Usage

Discussion in 'Scripting' started by Cypras, Sep 2, 2020.

  1. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    I've been trying to figure out how to use the League of Legends live API. I've had success using the endpoints like this: /lol/summoner/v4/summoners/by-name/{summonerName}

    but when it comes to using endpoints like this (for live game data): GET https://127.0.0.1:2999/liveclientdata/allgamedata

    I get the error "Cannot connect to destination host"

    Here is sample code I've been trying:

    Code (CSharp):
    1. private IEnumerator Test()
    2.     {
    3.         string url = "https://127.0.0.1:2999/liveclientdata/activeplayername";
    4.  
    5.         using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
    6.         {
    7.             yield return webRequest.SendWebRequest();
    8.  
    9.             string error = webRequest.error;
    10.  
    11.             if (error != null)
    12.             {
    13.                 Debug.LogError("[LoLAPI] - " + error);
    14.             }
    15.             else
    16.             {
    17.                 Debug.Log(webRequest.downloadHandler.text);
    18.             }
    19.         }
    20.     }
    Am I missing something?

    Thanks
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,944
    The first one looks like an API running on the internet on Riot's servers.

    The second one looks like a local server that I guess the LOL game client runs while you're playing. Do you have the LOL game client running when you're making this request? There also seem to be some extra requirements like installing/trusting the TLS root cert for the game client. Seems to be documented here: https://developer.riotgames.com/docs/lol#game-client-api_live-client-data-api
     
  3. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Thanks for the reply.

    How do I go about running a TLS root cert for the game client? That is documented there but it's not very helpful at all. Any clues on where to start? Thanks
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,944
  5. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    While running this code:

    Code (CSharp):
    1. private IEnumerator Test()
    2.         {
    3.             string url = "https://127.0.0.1:2999/liveclientdata/activeplayername";
    4.  
    5.             using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
    6.             {
    7.                 webRequest.certificateHandler = new BypassCertificate();
    8.  
    9.                 yield return webRequest.SendWebRequest();
    10.  
    11.                 string error = webRequest.error;
    12.  
    13.                 if (error != null)
    14.                 {
    15.                     Debug.LogError("[LoLAPI] - " + error);
    16.                 }
    17.                 else
    18.                 {
    19.                     Debug.Log(webRequest.downloadHandler.text);
    20.                 }
    21.             }
    22.         }
    Code (CSharp):
    1. using UnityEngine.Networking;
    2.  
    3. public class BypassCertificate : CertificateHandler
    4. {
    5.     protected override bool ValidateCertificate(byte[] certificateData)
    6.     {
    7.         //Simply return true no matter what
    8.         return true;
    9.     }
    10. }
    and being in an active game in LOL, it still returned the same error as original post.

    Any ideas?
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,944
    I suggest trying the curl command from the docs to make sure the game is actually listening before doing more work in Unity:
    Code (CSharp):
    1. curl --insecure https://127.0.0.1:2999/swagger/v3/openapi.json
     
  7. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Do I run that in terminal or something?