Microsoft Graph API を使用して を使用してグループを作成してPOST https://graph.microsoft.com/v1.0/groups
いますが、400 - Bad Request
応答があります。
私のコード:
string url = AuthenticationRequest.Microsoft_Graph_API_URL + "/groups";
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Authorization", "Bearer xxxxxxxxxxxxx");
WebRequests webReq = new WebRequests();
var ddd = new
{
description = "Group to help readers",
displayName = "Reader Assist",
groupTypes = new List<String>()
{
"Unified"
},
mailEnabled = true,
mailNickname = "rhelp",
securityEnabled = false
};
string body = JsonConvert.SerializeObject(ddd);
string response = webReq.PostRequestWithheaders(url, headers, body);
メソッドのコードPostRequestWithheaders
public string PostRequestWithheaders(string url, IDictionary<string, string> headers, string bodyData)
{
try
{
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
if (headers.Count > 0)
{
foreach (var item in headers)
{
webRequest.Headers.Add(item.Key, item.Value);
}
}
Stream dataStream = webRequest.GetRequestStream();
byte[] postArray = System.Text.Encoding.ASCII.GetBytes(bodyData);
dataStream.Write(postArray, 0, postArray.Length);
dataStream.Close();
WebResponse response = webRequest.GetResponse();
dataStream = response.GetResponseStream();
StreamReader responseReader = new StreamReader(dataStream);
string returnValue = "";
returnValue = responseReader.ReadToEnd().ToString();
responseReader.Close();
dataStream.Close();
response.Close();
return returnValue;
}
catch (Exception ex)
{
throw;
}
return "";
}
トークンはスコープを使用して生成されますopenid offline_access Calendars.ReadWrite.Shared profile email https://graph.microsoft.com/User.Read
このコードの何が問題なのか、誰でも助けてもらえますか?