I use the following code which is literally copied from Google's own .NET quickstart to list the files in your Google Drive account (the auth part has been adapted to use a refresh-token obtained by following the steps outlined here).
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Responses;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
using System;
using System.Diagnostics;
namespace GoogleTest {
class Program {
[STAThread]
static void Main(string[] args) {
var sw = Stopwatch.StartNew();
var secrets = new ClientSecrets() {
ClientId = "paste-your-client-id-here",
ClientSecret = "paste-your-client-secret-here"
};
var token = new TokenResponse { RefreshToken = "paste-your-refresh-token-here" };
var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer {
ClientSecrets = secrets
}),
"user",
token);
Console.WriteLine($"1: {sw.Elapsed}");
// Create the service.
var service = new DriveService(new BaseClientService.Initializer() {
HttpClientInitializer = credentials
});
Console.WriteLine($"2: {sw.Elapsed}");
// Define parameters of request.
var listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";
Console.WriteLine($"3: {sw.Elapsed}");
// List files.
var files = listRequest.Execute().Files;
Console.WriteLine($"4: {sw.Elapsed}");
if (files != null && files.Count > 0) {
foreach (var file in files) {
Console.WriteLine("{0} ({1})", file.Name, file.Id);
}
} else {
Console.WriteLine("No files found.");
}
Console.WriteLine($"5: {sw.Elapsed}");
}
}
}
Running the above code produces output along the following lines:
1: 00:00:00.1075210
2: 00:00:00.1881154
3: 00:00:00.1987953
4: 00:00:12.5158776
No files found.
5: 00:00:12.5166778
Press any key to continue . . .
In other words, the var files = listRequest.Execute().Files
call takes 10 seconds or more. Often it will even take up to 20 seconds.
Surely this cannot possibly be the normal response time for such a trivial request. Am I missing something here? As you can see, the Google Drive account in question does not even contain any files and is completely empty.