2017-08-05 78 views
1

我正在尝试通过Microsoft Graph API使用PATCH请求来更新OneNote页面。我不断收到Error 19999这本https://msdn.microsoft.com/en-us/office/office365/howto/onenote-error-codes意味着“未知错误”使用图形API更新OneNote页面

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

我可以验证该授权码是有效的(因为我能够做其他操作,如创建一个新的页面),并有必要的范围更新页面。任何人都可以帮助我在这里找出问题吗?

+0

的URL看起来应该是这样:HTTPS://graph.microsoft.com/v1.0/$metadata#users( '16f5a7b6-5a15-4568-aa5a-31bb117e9967')/ OneNote中/页..该代码无法识别“我” – jdweng

+0

您能指出我的来源吗?我从这里获得该网址https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/page_update –

+0

对于您的请求,您可以分享您从API中看到的回复(例如返回的所有标题,包括日期和X-correlationID?)。这将有助于诊断问题。 –

回答

1

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

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

非常感谢。 –