Acquisition of mailing group list 200 or more cannot be acquired.

Asked 2 years ago, Updated 2 years ago, 109 views

using Google.Apis.Admin.Directory.directory_v1;
using Google.Apis.Admin.Directory.directory_v1.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Util.Store;

# code

GroupsResource.ListRequest groupsResourceRequest=service.Groups.List();
groupsResourceRequest.Customer=customer;
IList<Group>g=groupsResourceRequest.Execute().GroupValue;

This method can only fetch up to 200.

When I asked a question on Google's github, there was advice like using Google.Apis.Drive.v3, but I don't know how to connect these two

https://github.com/google/google-api-dotnet-client/issues/905
https://gist.github.com/LindaLawton/0fe663bb9796acd875b676a9f1423a48

Please give me some advice.

c# google-api

2022-09-30 15:52

1 Answers

I think the link explains that you should issue the request multiple times using the result NextPageToken.

//Declare a list that summarizes the results of each request because the request is made multiple times.
List<Group>list=new List<Group>();;
string pageToken=null;
while(true)
{
    GroupsResource.ListRequest groupsResourceRequest=service.Groups.List();
    groupsResourceRequest.Customer=customer;
    // In the second and subsequent requests, the previously obtained NextPageToken is set.
    groupsResourceRequest.PageToken=pageToken;

    Groups groups = groupsResourceRequest.Execute();
    IList<Group>g=groups.GroupsValue;

    // Add the results of this request to the list.
    list.AddRange(g);
    // Store PageToken for the next request.
    pageToken=groups.NextPageToken;

    // If there is no token, the process is finished.   
    if(string.IsNullOrEmpty(pageToken)||!g.Any())
    {
        break;
    }
}


2022-09-30 15:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.