Skip to content

Instantly share code, notes, and snippets.

@tac-ljustiniano
Created August 31, 2022 05:18
Show Gist options
  • Save tac-ljustiniano/27bfcd08a3b7e3c6f8ed975ae7068638 to your computer and use it in GitHub Desktop.
Save tac-ljustiniano/27bfcd08a3b7e3c6f8ed975ae7068638 to your computer and use it in GitHub Desktop.
Get Users
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