我正在尝试使用C#中的Microsoft Graph对POST
进行findMeetingTimes
调用
https://graph.microsoft.com/v1.0/users/{userid}/findMeetingTimes
要获取用户个人资料数据,请执行以下操作:
IUserProfile IUserAuthentication.GetProfileData(string accessToken)
{
MicrosoftUserProfile profile = new MicrosoftUserProfile();
try
{
string url = "https://graph.microsoft.com/v1.0/me";
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Authorization", "Bearer " + accessToken);
WebRequests webReq = new WebRequests();
string response = webReq.GetRequest(url, headers);
profile = JsonConvert.DeserializeObject<MicrosoftUserProfile>(response);
}
catch (Exception)
{
throw;
}
return profile;
}
public string GetRequest(string url, IDictionary<string, string> headers)
{
string returned = "";
try
{
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
webRequest.Method = "GET";
if (headers.Count > 0)
{
foreach (var item in headers)
{
webRequest.Headers.Add(item.Key, item.Value);
}
}
System.Net.WebResponse resp = webRequest.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
returned = sr.ReadToEnd().Trim();
}
catch (Exception)
{
throw;
}
return returned;
}
答案 0 :(得分:1)
对您来说,最好的建议是直接使用Microsoft Graph Client Library,而不要使用HttpClient。安装库之后,然后 只需使用以下代码:
let stateCheck = setInterval(() => {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
if (getCookie('subscribe') !=1){
[~]
}
}
}, 100);
这是一种使代码更具可读性的简单有效的方法。
当然,您可以通过模仿以下代码来编写自己的逻辑:
graphClient.Me.FindMeetingTimes().Request().PostAsync()