简体   繁体   中英

C# - Edit OneNote Notebook on SharePoint using REST API

I would like to edit a OneNote NoteBook which is stored in a SharePoint Document Libary via a C# Console Application (because i want to use it to batch input pages into a notebook form a Windows 7 machine). Url looks like this: http_s://COMPANY.sharepoint.com/sites/SITE_ID/Documents/_New%20Tool/NOTEBOOK_NAME?d=SOME_ID

So i found this documentation for the OneNote REST API: One Note Api , and i have two questions:

  1. How do i get/request the Bearer Token? SDKs for this seem to be only available for Universal Windows Applications
  2. How do i get the correct API URI? As it states here i need some IDs for the URI, but i do not know which ones to use.

If anyone has any "quick start code" to begin with or a blog post, that would be great. The official examples on GitHub do not seem to be fitting my needs...

If you want to get a Bearer token from a console app, here are your options:

  1. Get a token from somewhere else (eg another app that gets tokens) and temporarily copy it to your console app
  2. Display (via a web control/browser) the sign in flow and extract the token from it into the console app. The user has to see the sign in UI at least once - there is no way around this unfortunately. The best example I can find of this is the following: https://github.com/googlesamples/oauth-apps-for-windows/tree/master/OAuthConsoleApp . You'd just have to change the URLs/scopes/AppId.

I'd suggest going with (1) or a different route (windows universal app), but if you do need it to be a console app... you'll need to essentially show a web control/browser with the sign in URL, then parse the code out of it once the user has signed in (or have the user paste it in).

Once you have the bearer token, you can read our blog post on how to use FromUrl to extract/edit content from a site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM