I'm experimenting with the Riot Games API. I know for sure that my URL is fine, my API key that I have to include is also fine; there is no reason that my request should return a 401. At first I thought it had to do with Eclipse, but putting the API in my browser also returns a 401 (in the JSON format that the API usually returns). I know there are forums for this, but I thought maybe someone here could point out if there was an error in my program:
public class APITry {
public static void main(String[] args) throws IOException{
URL LOLAPI = new URL("https://prod.api.pvp.net/api/lol/na/v1.1/summoner/by-name/RiotSchmick&api_key=<key>"); //<key> is, of course, replaced with my key
BufferedReader in = new BufferedReader(new InputStreamReader(LOLAPI.openStream()));
StringBuilder build = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null)
build.append(in.toString());
in.close();
String INFO = build.toString();
JSONParser prse = new JSONParser();
try {
Object obj = prse.parse(in);
JSONObject PARSED = (JSONObject) obj;
String message = (String) PARSED.get("message");
int summonerID = (int) PARSED.get("losses");
System.out.println("message:" + message);
System.out.println("retrieved, is " + summonerID);
} catch (ParseException e) {
e.printStackTrace();
System.out.println("parse exception");
} catch(NullPointerException e) {
e.printStackTrace();
} catch(FileNotFoundException e) {
e.printStackTrace();
}
}
My imports are all accounted for.