Last active
          November 4, 2018 02:35 
        
      - 
      
 - 
        
Save frankhu-2021/d5ba5b4882b80b5e218bd5a5a7b237bb to your computer and use it in GitHub Desktop.  
    Get 5 users from the Microsoft Graph API using ADAL .net
  
        
  
    
      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.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