我需要从日历中获取活动,并在活动中找出个人用户。
var graphServiceClient = new GraphServiceClient(...);
var events = graphServiceClient.Me.CalendarView.Request().GetAsync();
// ...
var attendee = events[0].Attendees[0];
// Is attendee a group or user?
// If a group, how do we expand it?
答案 0 :(得分:2)
我们可以通过检索用户/组来确定邮件地址是用户还是组。例如,我们可以通过以下REST获取特定组:
{{3 }}?$filter=mail+eq+'group1@yourtenant.onmicrosoft.com'
如果我们提供的电子邮件是用户,则响应将为空值,否则返回该组的信息。
要获取特定组的成员,我们可以通过上述请求返回id返回的请求:
https://graph.microsoft.com/v1.0/groups {GROUPID} /成员
以下是获取该组及其成员供您参考的代码。我建议您通过HttpClient进行REST,因为它更灵活,更高效。
public async Task GetGroup(string mailAddress) {
var groups = await graphserviceClient.Groups.Request().Top(10).GetAsync();
foreach (var group in groups.CurrentPage)
{
Console.WriteLine(group.Mail);
if (mailAddress.Equals(group.Mail))
return group.Id;
}
while (groups.NextPageRequest != null)
{
groups = await groups.NextPageRequest.GetAsync();
foreach (var group in groups.CurrentPage)
{
Console.WriteLine(group.Mail);
if (mailAddress.Equals(group.Mail))
return group.Id;
}
}
return null;
}
public async void GetMembers(string groupId)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "bearer " + _accessToken);
string serviceURL = String.Format("https://graph.microsoft.com/v1.0/groups/{0}/members?$select=mail", groupId);
var response = client.GetAsync(serviceURL).Result;
JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
foreach (var mail in json["value"].Values("mail"))
{
Console.WriteLine(mail);
}
}
<强>更新强>
我们需要使用“Group.Read.All”范围来阅读这些组: https://graph.microsoft.com/v1.0/groups/