Last active
January 1, 2019 01:20
-
-
Save frankhu-2021/436f98f3201d30bb8ba3ef43ce584a37 to your computer and use it in GitHub Desktop.
MicroosftGraphSDK Get Users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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