Skip to content

Instantly share code, notes, and snippets.

@LindaLawton
Created December 12, 2016 13:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindaLawton/0fe663bb9796acd875b676a9f1423a48 to your computer and use it in GitHub Desktop.
Save LindaLawton/0fe663bb9796acd875b676a9f1423a48 to your computer and use it in GitHub Desktop.
Uses page streamer to eat up your quota.
/// <summary>
/// Lists or searches files.
/// Documentation https://developers.google.com/drive/v3/reference/files/list
/// Generation Note: This does not always build correctly. Google needs to standardize things I need to figure out which ones are wrong.
/// </summary>
/// <param name="service">Authenticated Drive service. </param>
/// <param name="optional">The optional parameters. </param>
/// <returns>FileListResponse</returns>
public static Google.Apis.Drive.v3.Data.FileList ListAll(DriveService service, FilesListOptionalParms optional = null)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException("service");
// Building the initial request.
var request = service.Files.List();
// Applying optional parameters to the request.
request = (FilesResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);
var pageStreamer = new Google.Apis.Requests.PageStreamer<Google.Apis.Drive.v3.Data.File, FilesResource.ListRequest, Google.Apis.Drive.v3.Data.FileList, string>(
(req, token) => request.PageToken = token,
response => response.NextPageToken,
response => response.Files);
var allFiles = new Google.Apis.Drive.v3.Data.FileList();
allFiles.Files = new List<Google.Apis.Drive.v3.Data.File>();
foreach (var result in pageStreamer.Fetch(request))
{
allFiles.Files.Add(result);
}
return allFiles;
}
catch (Exception Ex)
{
throw new Exception("Request Files.List failed.", Ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment