gpt4 book ai didi

microsoft-graph-api - 微软图形 API : How to tell if an attendee is a group

转载 作者:行者123 更新时间:2023-12-01 13:47:05 24 4
gpt4 key购买 nike

我需要从日历中获取事件,并找出事件中的各个用户。

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?

最佳答案

我们可以通过检索用户/组来判断邮件地址是用户还是组。例如,我们可以通过下面的 REST 获取特定的组:

https://graph.microsoft.com/v1.0/groups ?$filter=mail+eq+'group1@yourtenant.onmicrosoft.com'

如果我们提供的电子邮件是用户,则响应将为空值,否则返回该组的信息。

而要获取特定组的成员,我们可以使用上述请求返回的 id 进行请求:

https://graph.microsoft.com/v1.0/groups/ {groupid}/成员

下面是获取群组和群组成员的代码,供大家引用。我建议您通过 HttpClient 创建 REST,因为它更加灵活和高效。

公共(public)异步任务 GetGroup(字符串邮件地址) {

    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”作用域来读取组: enter image description here

关于microsoft-graph-api - 微软图形 API : How to tell if an attendee is a group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37574735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com