본문 바로가기
에버노트 API 사용하기

스프링 웹개발에서 에버노트 API 사용하기

by 자유코딩 2018. 7. 28.

https://github.com/evernote/evernote-sdk-java

 

https://dev.evernote.com/doc/

 

스프링 프레임워크 기반 홈페이지에서 에버노트 API 를 사용해보고 싶었습니다.

 

사용 방법을 올립니다.

 

1 -> 5의 순서로 진행하시면 됩니다.

 

1. 사용 신청하기

 

2. Consumer 키 받기 , Consumer Secret 키 받기

 

3. 개발자 Token 발급 받기

 

4. 다운로드 하기 - Pom.xml 에 dependency 추가

 

5. 자바 코드 작성하기!

 

 

 

 

api를 신청합니다.

 

양식을 잘 작성해줍니다.

 

작성을 한번 틀렸었습니다.

 

Evernote Username은 사용하시는 에버노트 계정의 유저 이름을 입력하시면 됩니다.

 

Developer Name부터는 아무거나 입력하셔도 됩니다.

 

Basic Access 말고 Full Access 를 선택했습니다.

 

 

신청이 잘 되었다고 표시됩니다.

 

이제 개발자 토큰을 발급받습니다.

 

 

 

토큰의 종류가 2개입니다.

 

그런데 Production은 발급이 안됩니다.

 

SandBox로 발급받습니다.

 

 

토큰 생성 클릭합니다.

 

 

발급 받은 토큰은 잃어버리면 재발급 해야 됩니다. 메모장 같은 곳에 잘 저장해둡니다.

 

이제 깃허브로 갑니다.

 

 

install SDK , README 모두 github 주소로 이동합니다.

 

이동하면 코드 예제와 설명이 있습니다.

 

설치하는 방법도 있습니다.

 

스프링 프레임워크의 경우 pom.xml 에 dependency를 추가하면 됩니다.

 

 

프로젝트를 업데이트 해줍니다.

 

이제 코드를 작성하러 갑니다.

 

서비스 클래스를 아래와 같이 작성했습니다.

 

예제로 아주 유사한 코드가 제공되고 있습니다. 그것을 조금만 변경했습니다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.simple.service;
 
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.evernote.auth.EvernoteAuth;
import com.evernote.auth.EvernoteService;
import com.evernote.clients.ClientFactory;
import com.evernote.clients.NoteStoreClient;
import com.evernote.edam.type.Notebook;
import com.simple.dao.Mapper;
 
public class EvernoteSubscribeService implements Service {
 
    @Override
    public Map<String, Object> service(HttpServletRequest request, Mapper mapper){
        String developerToken = "여러분의 토큰";
        EvernoteAuth evernoteAuth = null;
        ClientFactory factory = null;
        NoteStoreClient noteStore = null;
        List<Notebook> notebooks = null;
                
        try {
            evernoteAuth = new EvernoteAuth(EvernoteService.SANDBOX, developerToken);
            factory = new ClientFactory(evernoteAuth);
            noteStore = factory.createNoteStoreClient();
            notebooks = noteStore.listNotebooks();
            
        } catch (Exception e) {
            // TODO: handle exception
        }
 
        for (Notebook notebook : notebooks) {
          System.out.println("Notebook: " + notebook.getName());
        }
        
        return null;
    }
}
 
cs

 

컨트롤러 함수

 

1
2
3
4
5
6
    @RequestMapping(value="/evernote_request")
    public String evernote_request(HttpServletRequest request) {
        EvernoteSubscribeService evernoteSubscribeService = new EvernoteSubscribeService();
        evernoteSubscribeService.service(request, mapper);
        return "main";
    }
cs

 

 

서비스 클래스를 보시길 바랍니다. 콘솔에 출력하라고 코드를 작성했습니다.

 

콘솔에는 아래와 같이 출력됩니다.

 

저는 이것을 보고 제 에버노트에 로그인 해봤습니다.

 

제가 API 를 신청한 계정의 노트에는 전혀 다른 내용이 들어있습니다.

 

이것을 보고 저 처럼 "왜 이러지?" 하는 분들이 있을 것 같아서 알려드립니다.

 

개발자 토큰 발급 받을때 NoteStore URL이라는 것이 있었습니다.

 

그게 이런 형식으로 적히게 됩니다. https://sandbox.evernote.com

 

뒤에는 몇자 더 적혀있습니다.

 

쉽게 말하면 evernote.com 에 저장되는게 아니고

 

sandbox.evernote.com 에 저장됩니다. sandBox API 를 신청해서 그렇습니다.

 

신청하고 노트 확인하는 것까지 알아봤습니다.

 

다음부터는 글 작성을 해보도록 하겠습니다.

 

 

댓글