【问题标题】:Update a OneNote page using Graph API使用 Graph API 更新 OneNote 页面
【发布时间】:2017-08-06 04:55:34
【问题描述】:

我正在尝试通过 Microsoft Graph API 使用 PATCH 请求更新 OneNote 页面。我不断收到Error 19999,据此https://msdn.microsoft.com/en-us/office/office365/howto/onenote-error-codes 表示“未知错误”

var pageId = settings.DefaultPage;
string requestUrl = $"https://graph.microsoft.com/v1.0/me/onenote/pages/{pageId}/content";
string body = @"{ 
{
'target':'body',
'action':'append',
'position':'after',
'content':'<div> added new </div>'}}";
var content = new StringContent(body, Encoding.UTF8, "application/json");
HttpRequestMessage req = new HttpRequestMessage()
{
    Method = new HttpMethod("PATCH"),
    Content = content,
    RequestUri = new Uri(requestUrl)
};
HttpClient client = new HttpClient()
{
    BaseAddress = new Uri(requestUrl),
};
client.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Bearer " + settings.MsaAccessCode);
HttpResponseMessage response = await client.SendAsync(req);

我可以验证授权码是否有效(因为我可以执行其他操作,例如创建新页面)并且具有更新页面所需的范围。谁能帮我找出这里的问题?

【问题讨论】:

  • 网址应如下所示:h t t p s://graph.microsoft.com/v1.0/$metadata#users('16f5a7b6-5a15-4568-aa5a-31bb117e9967')/onenote/pages ..代码无法识别“我”
  • 你能指出你的来源吗?我从这里得到了那个网址developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/…
  • 对于您的请求,您能否分享您从 API 看到的响应(例如返回的所有标头,包括日期和 X-correlationID?)。这将有助于诊断问题。
  • "me" 需要替换为有效用户。
  • 只有在应用调用“具有自己身份的 Microsoft Graph”developer.microsoft.com/en-us/graph/docs/concepts/… 时才需要明确提及用户

标签: c# uwp microsoft-graph-api onenote onenote-api


【解决方案1】:

您的 JSON 无效。这就是我相信你想要的。

[{
    "target": "body",
    "action": "append",
    "position": "after",
    "content": "<div> added new </div>"
}]

【讨论】:

  • 非常感谢。
猜你喜欢
  • 2021-04-23
  • 2020-07-11
  • 2022-10-07
  • 2020-12-13
  • 1970-01-01
  • 1970-01-01
  • 2021-09-26
  • 2020-09-05
  • 1970-01-01
相关资源
最近更新 更多