2017-08-05 77 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

非常感謝。 –