Created
August 31, 2022 05:18
-
-
Save tac-ljustiniano/27bfcd08a3b7e3c6f8ed975ae7068638 to your computer and use it in GitHub Desktop.
Get Users
This file contains 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
UsersResource.ListRequest request = _ds.Users.List(); | |
... | |
request.Domain = _domain; | |
Users uGapi = request.Execute(); | |
List<User> users = uGapi.UsersValue.ToList(); | |
... | |
int page = 1; | |
while(!string.IsNullOrEmpty(uGapi.NextPageToken) && page <= THRESHOLD) | |
{ | |
request.PageToken = uGapi.NextPageToken; // First page is null | |
uGapi = request.Execute(); | |
users.AddRange(uGapi.UsersValue.ToList()); | |
page++; | |
if(page > THRESHOLD && !string.IsNullOrEmpty(uGapi.NextPageToken)) | |
{ | |
// Error | |
break; | |
} | |
} | |
foreach (var userItem in users) | |
{ | |
// Key elements | |
list.Add(new UserData { | |
ID = userItem.Id, // Identity ID | |
PrimaryEmail = userItem.PrimaryEmail, // Primary email | |
... | |
Active = !(userItem.Suspended ?? false) // Is active | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment