taycaldwell / riot-api-java

Riot Games API Java Library
http://taycaldwell.github.io/riot-api-java/
Apache License 2.0
190 stars 73 forks source link

createProvider() #60

Closed fima-taf closed 8 years ago

fima-taf commented 8 years ago

Hi, I am working on some project with this api, and I want to try the tournament system.

To create a code I need to create tournament and before it the provider. it asks me for callbackUrl String.

The question is what is the url i need to give there while i am on the testing part?

Thanks in advance!

taycaldwell commented 8 years ago

The String is the callback URL in which the League of Legends servers will send data after a tournament game is completed.

This lets you receive game data (such as which team won/lost) after each tournament game finishes.

You should set up some URL that the League of Legends servers can make a callback to via HTTP POST.

For testing purposes, if you are just interested in generating tournament codes, and don't care for receiving data from the League of Legends servers after each game, you can just provide a dummy URL like "http://test.com".

If you are interested in this data, you will need to setup your server with a callback URL for the League of Legends servers to callback. It can be anything really... like "http://mysupercoolwebsite.com/api/awesomeCallbackURL". As long as it sends back a 200 response upon success, and is on port 80, you're golden.

More detailed information and examples can be found under the Server Callback section of the official Tournaments API Documentation.

fima-taf commented 8 years ago

First of all I want to thank you for the fast answering and the explanation, and to tell you that the API you have created is awesome!

I'v tried to use the "http://test.com", and i get an Exception - Forbidden. Any special reason I'v got this exception?

taycaldwell commented 8 years ago

Ah, common error. I believe you are receiving this error because you are using your normal API key in place of a Tournament API key.

Before you are able to use the Tournament API, you will need a Tournaments API Key. This is different from the default developer API key Riot provides you when you make an account on the Developer Portal, and is specifically used for everything related to the Tournaments API.

If you don't have a Tournament API Key, you should visit the Developer Portal dashboard, and 'Register a Project'. Make sure you specify that you are registering this project to use the Tournaments API using the drop-down they provide, or Riot will correct you and you will have to start the process all over again (been there, done that).

Once you register your project, Riot will look it over and provide you with a conditional demo tournament key that you can use.

If you are using v3.9 of the library, here's an example of Tournaments API code that passes a normal API key and a tournaments API key as two different parameters:


import net.rithms.riot.api.RiotApi;
import net.rithms.riot.api.RiotApiException;
import net.rithms.riot.constant.PickType;
import net.rithms.riot.constant.Region;
import net.rithms.riot.constant.SpectatorType;
import net.rithms.riot.constant.TournamentMap;
import net.rithms.riot.dto.Tournament.TournamentCode;

public class Example {

    public static void main(String[] args) throws RiotApiException {

        RiotApi api = new RiotApi("<API-KEY-HERE>", "<TOURNAMENT-API-KEY-HERE>",
                Region.NA);

        // Create a tournament provider for the NA region, and provide a
        // callback URL to which tournament game results in this region will be
        // posted.
        int providerId = api.createProvider(Region.NA, "https://test.com");

        // Create a tournament under this provider named "Test Tournament".
        int tournamentId = api.createTournament("Test Tournament", providerId);

        /*
         * Create a tournament code for a lobby with the following settings: -
         * Team Size: 5 - Map Type: Summoner's Rift - Pick Type: Blind Pick -
         * Spectator Type: All
         */
        String tournamentCode = api.createTournamentCode(tournamentId, 5, TournamentMap.SUMMONERS_RIFT,
                PickType.BLIND_PICK, SpectatorType.ALL);

        System.out.println("TournamentCode: " + tournamentCode);

        // Get data for the tournament code and print the lobby name
        TournamentCode tournamentCodeData = api.getTournamentCode(tournamentCode);
        System.out.println("Lobby Name: " + tournamentCodeData.getLobbyName());
    }

}

Hope this helps!

fima-taf commented 8 years ago

So as I understood, to get the tournament API key, i need to register my project at Riot's developer portal first, and after they approve my project I will get from them the key? And only after that i can start testing the tournament API?

taycaldwell commented 8 years ago

Yes, that is correct. Not sure why they do it that way, but they have their reasons.