我不能避免收到以下错误:无法发布到OneNote客户
StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
这里是我的代码:
public async Task<string> SendPostRequest(string _AccessToken)
{
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + _AccessToken);
string date = GetDate();
string simpleHtml = "<html>" +
"<head>" +
"<title>A simple page created from basic HTML-formatted text</title>" +
"<meta name=\"created\" content=\"" + date + "\" />" +
"</head>" +
"<body>" +
"<p>This is a page that just contains some simple <i>formatted</i> <b>text</b></p>" +
"<p>Here is a <a href=\"http://www.microsoft.com\">link</a></p>" +
"</body>" +
"</html>";
var createMessage = new HttpRequestMessage(HttpMethod.Post, _GraphAPIEndpoint)
{
Content = new StringContent(simpleHtml, Encoding.UTF8, "text/html")
};
HttpResponseMessage response = await httpClient.SendAsync(createMessage);
return response.ToString();
}
这里是GraphEndpoint:
private string _GraphAPIEndpoint ="https://www.onenote.com/api/v1.0/pages";
一切看起来不错与登录和身份验证。我得到一个令牌等
这里是让我的令牌代码:
private const string _ClientID = "981c0157-69ec-4f42-8ec6-xxxxxxxxxxxxx";
public static PublicClientApplication clientApplication = new PublicClientApplication(_ClientID);
private AuthenticationResult authResult = null;
authResult = await App.clientApplication.AcquireTokenAsync(_Scopes);
if (authResult != null)
{
string response = await SendPostRequest(authResult.AccessToken);
}
你在做什么平台? ASP.NET? Windows商店? –