Skip to content

Instantly share code, notes, and snippets.

@frankhu-2021
Last active November 4, 2018 02:35
Show Gist options
  • Save frankhu-2021/d5ba5b4882b80b5e218bd5a5a7b237bb to your computer and use it in GitHub Desktop.
Save frankhu-2021/d5ba5b4882b80b5e218bd5a5a7b237bb to your computer and use it in GitHub Desktop.
Get 5 users from the Microsoft Graph API using ADAL .net
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net.Http;
using System.Net.Http.Headers;
static async Task getMembers()
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
Console.WriteLine("\n \n Retrieving users {0}", DateTime.Now.ToString());
HttpResponseMessage response = await httpClient.GetAsync(resourceUri + "/v1.0/users?$top=5");
if (response.IsSuccessStatusCode)
{
// Read the response and output it to the console.
string users = await response.Content.ReadAsStringAsync();
Console.WriteLine("\n \n Printing out Users \n \n");
Console.WriteLine(JsonPrettify(users));
Console.WriteLine("Received Info");
}
else
{
Console.WriteLine("Failed to retrieve To Do list\nError: {0}\n", response.ReasonPhrase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment