【问题标题】:Google Drive Files.list: 500 errorGoogle Drive Files.list:500 错误
【发布时间】:2013-03-28 15:08:05
【问题描述】:

对于我们的应用程序,我们使用的是具有 2-legged 授权的 Google Drive SDK。 我们使用 Drive SDK 很长时间了,但今天我们遇到了 Files.list API 的新问题 (https://developers.google.com/drive/v2/reference/files/list)。对于某些来自不同域的用户,我们收到以下错误:

{ "error": { "code": 500, "message": null } }

Drive SDK 一切正常吗?这个错误是什么意思?

【问题讨论】:

    标签: google-drive-api


    【解决方案1】:

    我推荐阅读这个post,它帮助我使用 Android 配置和连接到 Google Drive

    编辑:

    我有同样的 500 错误服务器,为了避免这个错误谷歌推荐 Exponential backoff,根据他们:

    指数退避是网络的标准错误处理策略 客户端定期重试失败请求的应用程序 在越来越多的时间内。如果请求量很大或 繁重的网络流量导致服务器返回错误,指数级 退避可能是处理这些错误的好策略。反过来, 它不是处理与不相关的错误的相关策略 速率限制、网络容量或响应时间,例如无效 未找到授权凭据或文件错误。

    使用得当,指数退避可以提高效率 带宽使用,减少了获得 成功响应,并最大化请求的吞吐量 并发环境。

    示例:

    安卓代码:

    FileList files = null;
    
    for (int n = 0; n < 5; ++n) {
    
       try {
          setStatus("trying n = " + n);
          files = service.files()
            .list()
            .setMaxResults(1)
            .setQ("mimeType = 'application/vnd.google-apps.folder' and title = 'folder_title'")
            .execute();
       }
       catch (GoogleJsonResponseException e)
       {
          if (e.getDetails().getCode() == 500) {
            try {
                Thread.sleep((1 << n) * 1000 + randomGenerator.nextInt(1001));
                setStatus("sleep() n = " + n);
            } catch (InterruptedException e1) {
                // TODO Auto-generated catch block
                setStatus("InterruptedException n = " + n + " " + e1.getMessage());
                e1.printStackTrace();
            }
          }
       }
    
    }
    

    我已经测试了这段代码,并在最后一次尝试中成功连接

    Google 建议对 4xx 和 5xx 服务器使用指数退避 error

    4xx server 错误主要是身份验证问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      相关资源
      最近更新 更多