Unpaywall API란?
학술 논문의 무료 오픈 액세스 버전을 찾을 수 있도록 도와주는 API
주로 연구자 및 개발자 및 기관들이 논문 접근성을 높이기 위해 사용함.
1. Unpaywall API란?
● 기능 : DOI(Digital Object Identifier)
● 제공방식 : RESTful API
● 요금 : 무료
● 사용제한 : 과도한 요청 방지 위해 일정 요청 속도 제한 존재
2. API 사용 방법
● API 엔드포인트
(1) 기본 요청 URL
https://api.unpaywall.org/v2/{DOI}?email={YOUR_EMAIL}
- {DOI} : 논문의 DOI를 입력
- {YOUR_EMAIL} : 요청하는 사용자의 이메일 (필수)
(2) 예제
https://api.unpaywall.org/v2/10.1038/s41586-020-2649-2?email=your@email.com
(3) 응답 예시 [JSON]
{
"doi":"10.1038/s41586-020-2649-2",
"is_oa":true,
"best_oa_location":{
"url":"https://www.nature.com/articles/s41586-020-2649-2.pdf"
},
"title":"Title of the research paper",
"journal_name":"Nature"
}
- is_oa : 무료로 접근 가능한 논문인지 여부(true 또는 false)
- best_oa_location_url : 무료로 논문을 다운로드할 수 있는 링크
- title : 논문 제목
- journal_name : 저널 이름
3. API 호출 방법
Spring에서는 HTTP 요청을 위해 RestTemplate 또는 HttpURLConnection을 사용할 수 있다.
(1) RestTemplate 을 사용한 API 호출
RestTemplate은 Spring에서 제공하는 HTTP 클라이언트이며, Spring Framework에서도 사용 가능하다.
Spring 3.x부터 지원되며, Spring 5.x 이하에서는 가장 적합한 방식이다.
✅ RestTemplate을 이용한 API 호출
import org.springframework.web.client.RestTemplate;
import org.springframework.http.ResponseEntity;
public class UnpaywallClient {
private RestTemplate restTemplate;
public UnpaywallClient() {
this.restTemplate = new RestTemplate();
}
public String getUnpaywallData(String doi, String email) {
String url = String.format("https://api.unpaywall.org/v2/%s?email=%s", doi, email);
// API 호출
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
// 결과 반환
return response.getBody();
}
public static void main(String[] args) {
UnpaywallClient client = new UnpaywallClient();
String response = client.getUnpaywallData("10.1038/s41586-020-2649-2", "your@email.com");
System.out.println(response);
}
}
→ RestTemplate을 사용하여 GET 요청을 보냄
→ ResponseEntity<String>을 이용해 API 응답을 문자열로 받음
→ main 메서드에서 직접 실행 가능
✅ HttpURLConnection 을 이용한 API 호출
Spring이 아닌 순수 Java 방식으로 API를 호출하고 싶다면 HttpURLConnection을 사용할 수 있다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class UnpaywallClient {
public String getUnpaywallData(String doi, String email) {
String urlString = String.format("https://api.unpaywall.org/v2/%s?email=%s", doi, email);
try {
// URL 객체 생성
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// 응답 코드 확인
int responseCode = connection.getResponseCode();
if (responseCode == 200) { // HTTP OK
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
return response.toString();
} else {
return "API 호출 실패: 응답 코드 " + responseCode;
}
} catch (Exception e) {
return "API 호출 중 오류 발생: " + e.getMessage();
}
}
public static void main(String[] args) {
UnpaywallClient client = new UnpaywallClient();
String response = client.getUnpaywallData("10.1038/s41586-020-2649-2", "your@email.com");
System.out.println(response);
}
}
→ Java의 HttpURLConnection을 이용해 GET 요청을 보냄
→ BufferedReader로 응답을 읽어와 문자열로 반환
→ 오류가 발생하면 예외 메시지를 출력
✅ Unpaywall API 응답 예시 [JSON]
{
"doi": "10.1038/s41586-020-2649-2",
"is_oa": true,
"best_oa_location": {
"url": "https://www.nature.com/articles/s41586-020-2649-2.pdf"
},
"title": "Title of the research paper",
"journal_name": "Nature"
}
- best_oa_location.url 값이 무료 논문의 다운로드 링크임.
4. API 사용 시 주의사항
● 반드시 이메일을 포함하여 요청해야 함
● DOI가 정확해야함(일부 논문은 무료로 제공되지 않을 수 있음)
● 과도한 요청 제한 : 대량 요청 시 사전 협의 필요(연락처: team@impactstory.org)
5. Unpaywall API 공식 문서
https://unpaywall.org/products/api
Unpaywall
unpaywall.org
결론적으로
- Spring 환경이라면 RestTemplate을 사용하는 것이 간편하고 효율적이다.
- Spring이 없거나, Java 기본 기능을 원한다면 HttpURLConnection을 사용할 수 있다.
'M-Plus' 카테고리의 다른 글
| [검색성능향상] 인덱스 사용하기 (0) | 2025.02.22 |
|---|---|
| CrossRef(크로스레프) 검색 API 사용법 (2) | 2025.02.07 |