Jump to content
kernelfreak

Evernote Oauth with Java

Recommended Posts

Hello friends,

I am working on a Java project in which we would wish to provide Evernote functionality for our app in which we could sync notes, attachments, etc to & fro Evernote. For this to work, I would like to authenticate against Evernote server and then persist the tokens in our database so we can provide services even when user is not logged into Evernote.

To achieve this, I have added Scribe library and Evernote java SDK in POM.xml. Unfortunately, I am unable to find any examples of how is the mechanism to authenticate against the server and then which tokens are sent from evernote, which ones are for future usage. I am unable to find documentation for the same. I have some code which worked with a developer token, and only a patch of OAuthService.

Can someone help me the authentication mechanism and which tokens to save and later consume?

Please note, I am using Spring-MVC as a platform.


Developer token code :
 

        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();

 

Authentication code :
 

 @Override
    public void checkOutEverNote() throws Exception {

        OAuthService service = new ServiceBuilder()
                .provider(EvernoteApi.Sandbox.class)
                .apiKey(CLIENT_KEY)
                .apiSecret(CLIENT_SECRET)
                .callback("http://localhost:8080/recievetoken")
                .build();
        Token requestToken = service.getRequestToken();
        String authUrl = service.getAuthorizationUrl(requestToken);

    }

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...