Jump to content

Java based OAuth2 authentication for Evernote(Not JSP, scriptlets)


Recommended Posts

Hello friends,


I am working on integrating Evernote with our webapp which is Spring-MVC based. The main purpose I have is the user can sync data between Evernote and our webapp.

Now, to achieve this, I must connect and authenticate with Evernote. To achieve this, I am unable to find any Java based samples. I only found https://github.com/evernote/evernote-sdk-java/blob/master/sample/oauth/src/main/webapp/index.jsp , which is a JSP file. I don't even understand why the developers today are putting Java code inside JSP. It's not even recommended.


I don't want to use that approach and whenever I look for some OAuth code, I can only find only portions of code posted by other users like https://discussion.evernote.com/topic/32566-oauth-and-java-some-help-needed/


Is there anyone out there who has some useful code with Java, and suitable for Spring environment where I can call methods in Controller and authenticate, and after redirect I can process data.


These are the tokens I have, developer token, NoteStore URL, Consumer Key, Consumer Secret.


Here is my code till now :

Controller :@Controllerpublic class EverNoteController extends MasterController{    @RequestMapping(value = "/tryevernote")    public String tryEverNote() throws Exception {        this.localEvernoteService.tryEverNote();        return "redirect:/dashboard";    }}Service Layer :@Service@Transactionalpublic class LocalEvernoteServiceImpl implements LocalEvernoteService {    private UserStoreClient userStore;    private NoteStoreClient noteStore;    private String newNoteGuid;    @Override    public void tryEverNote() throws Exception{        EvernoteAuth evernoteAuth = new EvernoteAuth(EvernoteService.SANDBOX, AUTH_TOKEN);        ClientFactory factory = new ClientFactory(evernoteAuth);        userStore = factory.createUserStoreClient();        boolean versionOk = userStore.checkVersion("Evernote EDAMDemo (Java)",                com.evernote.edam.userstore.Constants.EDAM_VERSION_MAJOR,                com.evernote.edam.userstore.Constants.EDAM_VERSION_MINOR);        if (!versionOk) {            System.err.println("Incompatible Evernote client protocol version");            System.exit(1);        }        // Set up the NoteStore client        noteStore = factory.createNoteStoreClient();        System.out.println("Listing notes:");        // First, get a list of all notebooks        List<Notebook> notebooks = noteStore.listNotebooks();        for (Notebook notebook : notebooks) {            System.out.println("Notebook: " + notebook.getName());            // Next, search for the first 100 notes in this notebook, ordering            // by creation date            NoteFilter filter = new NoteFilter();            filter.setNotebookGuid(notebook.getGuid());            filter.setOrder(NoteSortOrder.CREATED.getValue());            filter.setAscending(true);            NoteList noteList = noteStore.findNotes(filter, 0, 100);            List<Note> notes = noteList.getNotes();            for (Note note : notes) {                System.out.println(" * " + note.getTitle());            }        }        System.out.println();    }    @Override    public void checkOutEverNote() throws Exception {    }}

Any help would be appreciated.

Link to comment


This topic is now archived and is closed to further replies.

  • Create New...