[LOL 자유랭크 분석] #4. Riot API 이용하기

[LOL 자유랭크 분석] #4. Riot API 이용하기

#1~#3까지 해서 만든 소환사 이름 목록을 Riot API에서 전적 검색을 하기 위한 puuid 목록으로 새로 만들기 위해 API 요청하는 법을 찾아봤다. Riot API를 활용하기 위한 준비는 이 글을 따라해봤다. http라든지 api라든지 사실 제대로 아는 게 없어서 너무 어렵고 막막하다..

검색한 내용 + 알게 된 내용 + 해결한 내용?

1. apache httpclient library를 추가해서 http client를 이용한 통신(아마) 등의 기능을 수행할 수 있는 것 같다.

2. 분명 라이브러리를 제대로 추가했는데 java.lang.noclassdeffounderror이라는 오류 메시지가 자꾸 떠서 몇 시간을 헤매다 라이브러리를 module path가 아니라 class path에 추가했더니 괜찮아졌다.

3. replace를 사용해 문자열에서 특정 문자를 바꿀 수 있다. 가령 공백(" ")을 %20으로

4. api에 접근할 때 만료된 키를 사용해서 403 에러가 떴다.

아직 모르는 점

1. module path, class path는 뭘까? 왜 둘 중 하나를 골라서 라이브러리를 추가해야 하는 걸까?

2. http, json, header, html, xml, 웹 어쩌구 등등 모르는 게 너무 많아서 머리가 터질 것 같다.

3. 유효한 키로 바꾸고 첫 요청은 200으로 잘 갔다. 같은 방식으로 소환사 이름만 바꿔서 반복했는데 401 에러가 뜬다. 도대체 왜일까.. 글 쓰다 보니 알게 된 건데 401 에러가 뜨는 애들은 소환사 이름이 한글이다. 한글 설정에 뭔가 문제가 있나보다. 확인해봐야지

import java.io.*; import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.hc.core5.http.HttpResponse; public class Getpuuid { public static void main(String[] args) { //API KEY String key = "키는 비밀"; //Members.txt 읽기 File f1 = new File("Members.txt"); try( FileReader fr = new FileReader(f1); BufferedReader br = new BufferedReader(fr); ){ String readline = null; while( ( readline = br.readLine() ) != null ) { if(readline.equals("---Members---")) {continue;} String name = readline; String summonerName = name.replaceAll(" ", "%20"); String requestURL = "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + summonerName + "?api_key=" + key; //검색하기 try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpGet getRequest = new HttpGet(requestURL); HttpResponse response = httpclient.execute(getRequest); System.out.println(requestURL); System.out.println(response); }; } } catch(IOException e) { System.out.println(e.toString()); } } }

from http://fatshark.tistory.com/7 by ccl(A) rewrite - 2021-12-27 02:02:09