2

I am interested in writing a Java application that can access my OneNote notebooks via the OneNote API. I am not sure how to gain access to that API from within Java. Can anybody point me to an example of how to get started here? I use Eclipse as my development environment.

Kai
  • 38,985
  • 14
  • 88
  • 103
singrass
  • 73
  • 2
  • 5
  • http://stackoverflow.com/questions/4567055/read-microsoft-works-and-or-one-note-files-from-java – nafas Aug 14 '14 at 11:17
  • http://msdn.microsoft.com/en-us/library/office/dn575422(v=office.15).aspx – Eugene Aug 14 '14 at 11:18
  • Thank you nafas, upma, and Adi for your very swift replies. I'm afraid that I'm still a little bit confused. I would love to be able to use the Microsoft provided REST Apis or the Microsoft COM Apis to get to OneNote functionality from within my Java desktop application. However, I do not know what I need to do in Eclipse to be able to access those APIs. Ultimately, I would like to be able to create an object that is of type Application...such as Application myApp = new Application(); and proceed from there, but I can't figure out how to get the OneNote Application class available to me. – singrass Aug 14 '14 at 13:20

3 Answers3

1

This as straightforward process.

The 3 steps would be:

1) create a OneNote application on the OneNote developper's page. More info here https://dev.onedrive.com/app-registration.htm. This is a one time action.

2) your java application should then provide an authentification mechanism and a tolken-refresh mechanism.

See this post for more info on the authentification mechanism part : Getting a OneNote token with Java. This post is about the OAuth 2.0 flow 'Authorization code grant flow'. More info here https://msdn.microsoft.com/en-us/library/hh243647.aspx#flows

3) your java application calls adhoc API Rest methods to retreive the needed informations.

Example to retrieve all your notebooks (using OkHttp for Http requests):

private final static String NOTEBOOKS_ENDPOINT = "https://www.onenote.com/api/v1.0/me/notes/notebooks";


public Notebooks readAllNoteBooks() {

    try {
        if (client == null)
            client = new OkHttpClient();
        Request request = createOneNoteRequest(a_valid_tolken, NOTEBOOKS_ENDPOINT);
        Response response = client.newCall(request).execute();
        JsonObject content = UrlHelper.parseResponse(response);
        System.out.println(content);

        return Notebooks.build(content.get("value"));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

public static Request createOneNoteRequest(String mAccessToken, String url) {

    Request.Builder reqBuilder = new Request.Builder();
    reqBuilder.url(url);
    reqBuilder.header("Authorization", "Bearer " + mAccessToken);

    return reqBuilder.build();

}

NoteBooks and NoteBook are 2 tiny classes matching the key attributes from the OneNote objects.

Community
  • 1
  • 1
lvr123
  • 524
  • 6
  • 24
0

Microsoft has provided REST apis for accessing One note functionalities like creating and accessing notes. See OneNote Rest API reference.

Adi
  • 2,364
  • 1
  • 17
  • 23
0

singrass,

In addition to the above replies, the Android OneNote API sample may also help you. There is no OneNote application class that you can create (unless you want to create your own). You simply call the API through the HttpClient. If you are unfamiliar on how to call REST APIs in Java in general, this thread may help you.

-- James

Community
  • 1
  • 1
JamesLau-MSFT
  • 284
  • 1
  • 4