OneNote API 创建页面 C#

OneNote API Create Page C#

我正在尝试通过 OneNote 创建新页面 API。我的问题是,我是否必须使用 Live SDK 来创建新页面,或者我是否可以只使用从我的 OneNote API Dekstop 应用程序获得的访问令牌?这是我创建新页面的代码:

        private async Task CreateTestPage()
        {
            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "tokenString");


                string sampleHtml = @"<html>
    <head>
        <title>A sample page</title> 
    </head>
    <body>  
        <p>This is a page that has some info</p>
    </body>
</html>";

                var createMessage = new HttpRequestMessage(HttpMethod.Post, _pagesEndPOint)
                {
                    Content = new StringContent(sampleHtml, Encoding.UTF8, "text/html")
                };

                HttpResponseMessage response = await client.SendAsync(createMessage);
                response = await client.SendAsync(createMessage);

                await response.Content.ReadAsStringAsync();   
            }
            catch (Exception ex) { }
        }

我没有收到任何错误,但是当我 运行 应用程序时它没有创建任何新页面。另外,我在 Word Add in 中创建它,所以我在 Add In 方法中调用此方法 CreateTaskPage()。

任何关于启动和 运行ning 的帮助都会非常有帮助,谢谢 :D

我建议您使用 MS Graph API 和 SDK - 您可以使用 OneNote API 做任何事情,但它们 SDKs/docs 更广泛(它们甚至有 C# SDK)

您可以在控制台中试用(查看 OneNote 部分)

https://developer.microsoft.com/en-us/graph/graph-explorer