Skip to content

Instantly share code, notes, and snippets.

@frankhu-2021
Last active January 1, 2019 01:20
Show Gist options
  • Save frankhu-2021/436f98f3201d30bb8ba3ef43ce584a37 to your computer and use it in GitHub Desktop.
Save frankhu-2021/436f98f3201d30bb8ba3ef43ce584a37 to your computer and use it in GitHub Desktop.
MicroosftGraphSDK Get Users
using Microsoft.Graph;
static async Task getUsersUsingGraphServiceClient()
{
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
return Task.FromResult(0);
}));
var users = await graphServiceClient.Users.Request().Top(5)
.GetAsync();
Console.WriteLine("\n Printing out first 5 users \n");
for (int index = 0; index < users.CurrentPage.Count; ++index)
Console.WriteLine(users.CurrentPage[index].DisplayName);
while (users.NextPageRequest != null)
{
Console.WriteLine("\n Press Enter to get the next 5 users \n");
Console.ReadLine();
Console.WriteLine("\n Getting Next Page of Users \n");
users = await users.NextPageRequest.GetAsync();
Console.WriteLine("\n Printing Next 5 users \n");
for (int index = 0; index < users.CurrentPage.Count; ++index)
Console.WriteLine(users.CurrentPage[index].DisplayName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment