简体   繁体   中英

How do I get all Teams in MS Graph C#?

I have created a Team in the group successfully, now I need to cycle through the Teams so I can get their names and IDs.

I have tried the following code but without any success.

IGraphServiceTeamsCollectionPage teams = graphServiceClient
    .Teams
    .Request()
    .GetAsync()
    .Result;

foreach (Team team in teams)
{
    Console.WriteLine(team.Id);
}

I get

Code: UnknownError
Message: 
{
    "message":"No HTTP resource was found that matches the request URI 'https://api.teams.skype.com/v1.0/teams'."
}

I've also tried doing the same against Groups without success:

var groups = await graphServiceClient.Groups
    .Request()
    .GetAsync();

foreach (var group in groups)
{
    Console.WriteLine(group.DisplayName);
    Console.WriteLine(group.Team.Id);
}

Now I get the displayName of the Group, but when trying to access the Group's Team Id I get

Object reference not set to an instance of an object.

EDIT:

I have realized that Group ID = Teams ID, however, last week I was able to update the specific team with the following command:

await graphServiceClient
    .Teams[groupID]
    .Request()
    .UpdateAsync(team3);

but now it does not work and says:

No team found with Group Id {9032fa63-50bb-4....}

I have confirmed in PowerShell and Graph Explorer, that the Id is correct and, as I've said, it worked on Friday of last week.

Further to my comment, it seems the PageIterator class doesn't work with group collection that's returned (or I'm doing something wrong, which is possible!). In any event, this code works for getting all the groups with Teams in my environment, so you should be able to pass the Id property of each group to the Teams endpoint in Graph to carry on:

var groups = await client.Groups.Request().Select("id,displayName,resourceProvisioningOptions").Filter("resourceProvisioningOptions/Any(x:x eq 'Team')").GetAsync();
do
{
    foreach(var g in groups)
        {
            Console.WriteLine(g.DisplayName);
            Console.WriteLine(g.Id);
        }
        if(groups.NextPageRequest != null)
        {
            groups = await groups.NextPageRequest.GetAsync();
        }
}
while (groups.NextPageRequest != null);

Note that filtering on resource provisioning options requires using the Beta endpoint in Graph, this currently isn't available in V1.

I am using the groupID which is equal to teamID.

 var groups = await graphServiceClient.Groups.Request().GetAsync();
 foreach (var group in groups)
 {
   Console.WriteLine(group.DisplayName);
   Console.WriteLine(group.Id);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM