首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Drive API速度极慢

问Google Drive API速度极慢
EN

Stack Overflow用户
提问于 2021-04-02 09:14:58
回答 1查看 358关注 0票数 0

我使用从谷歌自己的.NET quickstart复制的以下代码来列出您的Google Drive帐户中的文件(身份验证部分已调整为使用通过遵循here概述的步骤获得的刷新令牌)。

代码语言:javascript
复制
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}");
        }
    }
}

运行上面的代码会产生以下代码的输出:

代码语言:javascript
复制
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 . . .

换句话说,var files = listRequest.Execute().Files调用需要10秒或更长时间。通常情况下,这甚至需要20秒。

当然,对于如此琐碎的请求,这不可能是正常的响应时间。我是不是漏掉了什么?正如你所看到的,有问题的Google Drive帐户甚至不包含任何文件,并且是完全空的。

EN

回答 1

Stack Overflow用户

发布于 2021-04-06 23:38:25

Google Apis的响应时间取决于很多变量。

  1. 当你的电话进来的同时,其他用户在服务器上做什么
  2. 你的电话在一天中的什么时间进来会增加其他人也在运行他们的cron作业的机会。
  3. 你的互联网速度。

你需要记住,这是一个免费的api,你可以得到你想要的东西。是的,有时呼叫返回速度很慢,但您不会为此付费。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66913349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档