2017-09-26 166 views
1

,我發現了以下錯誤:錯誤的請求錯誤400 MS-OneNote的圖形API

{ 
     StatusCode: 400, 
     ReasonPhrase: 'Bad Request', 
     Version: 1.1, 
     Content: System.Net.Http.StreamContent, 
     Headers: 
     { 
      client-request-id: 09bcf6bf-1c4a-4f9d-9713-42dfbed17ecd 
      request-id: 09bcf6bf-1c4a-4f9d-9713-42dfbed17ecd 
      Transfer-Encoding: chunked 
      x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"South Central US","Slice":"SliceB","ScaleUnit":"002","Host":"AGSFE_IN_3","ADSiteName":"SAN"}} 
      Duration: 395.8064 
      Cache-Control: private 
      Date: Tue, 26 Sep 2017 17:28:22 GMT 
      Content-Type: application/json 
     } 
    } 

當我使用此代碼來創建一個筆記本新的一節:

/// Create a new Section with the Patient Name as the displayName 
tempSectionName = LastNameEdit.Text.ToString() + " " + FirstNameEdit.Text.ToString(); 
string url = "https://graph.microsoft.com/v1.0/me/onenote/"; 

CreateSectionInNotebook(Globals.CurrentEMRNotebookID, tempSectionName, url); 

} 

/// <summary> 
/// Create a section with a given name under a given notebookId 
/// </summary> 
/// <param name="notebookId">parent notebook's Id</param> 
/// <param name="sectionName">name of the section to create</param> 
/// <param name = "apiRoute" ></ param > 
/// <remarks>Create section using a application/json content type</remarks> 

private async void CreateSectionInNotebook(string notebookId, string sectionName, string apiRoute) 
{ 
    var client = new HttpClient(); 

    // Note: API only supports JSON response. 
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 

    // Not adding the Authentication header would produce an unauthorized call and the API will return a 401 
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken); 

    // Prepare an HTTP POST request to the Sections endpoint 
    // The request body content type is application/json and require a name property 
    var createMessage = new HttpRequestMessage(HttpMethod.Post, apiRoute + @"notebooks/" + notebookId + "/sections") 
    { 
     Content = new StringContent("{ name : '" + WebUtility.UrlEncode(sectionName) + "' }", Encoding.UTF8, "application/json") 
    }; 

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

我有試圖匹配來自OneNote Service Samples Win Universal的輸入,但它使用OneNote API。

如果Microsoft Graph Explorer擴展了MSGraph/OneNote功能(如APIgee)對於OneNote API的功能,那將會很不錯。

回答

0

的MS圖形探險家確實有OneNote的樣本 - 看爲他們在左邊。