【发布时间】:2016-12-13 07:47:47
【问题描述】:
我正在尝试使用 Ms Graph API 连接到 Outlook 并下载附件。我到现在写的是
private static async Task<HttpWebRequest> createHttpRequestWithToken(Uri uri)
{
HttpWebRequest newRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
string clientId = "myClientId";
string clientSecret = "myClientSecret";
ClientCredential creds = new ClientCredential(clientId, clientSecret);
AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/myAzureAD/oauth2/token");
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds);
newRequest.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + authResult.AccessToken);
newRequest.ContentType = "application/json";
return newRequest;
}
我正在使用它来调用我需要的图形 API。因此,首先,我尝试调用此 URL:
Uri uri = new Uri(("https://graph.microsoft.com/v1.0/users/myEmailId/messages"));
HttpWebRequest request = createHttpRequestWithToken(uri).Result;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
运行代码后,我收到 HttpStatusCode 200 的响应,但 Content-Length 为 -1。我目前被困在这里。有人可以帮我解决哪里出错/如何进一步调试这段代码。
提前致谢。
【问题讨论】:
标签: c# azure outlook office365 microsoft-graph-api