【问题标题】:Google Docs API returns a 503 Service Unavailable when uploading a file. Has something changed?上传文件时,Google Docs API 返回 503 Service Unavailable。有什么改变吗?
【发布时间】:2013-06-04 21:06:38
【问题描述】:

我有使用 Google Docs API 的应用程序。直到最近,使用 HTTP 端点的上传一直运行良好。最近上传突然开始报错。第一次调用创建会话(返回可恢复的 URL)工作正常,并返回可恢复的 URL。尝试将文件内容发送到可恢复的 URL 会引发 503。

引发错误的代码的相关部分是这样的:

        URL url = new URL(resumableFileUploadUrl);
        conn = (HttpURLConnection) url.openConnection();
        conn.addRequestProperty("client_id", OAuth2Client.CLIENT_ID);
        conn.addRequestProperty("client_secret", OAuth2Client.CLIENT_SECRET);
        conn.setRequestProperty("Authorization", "OAuth " + GetAuthToken());

        conn.setRequestProperty("X-Upload-Content-Length", String.valueOf(fileContents.length())); //back to 0
        conn.setRequestProperty("X-Upload-Content-Type", "text/xml");
        conn.setRequestProperty("Content-Type", "text/xml");
        conn.setRequestProperty("Content-Length", String.valueOf(fileContents.length()));
        conn.setRequestProperty("Slug", fileName);

        if(isUpdate)
        {
            conn.setRequestProperty("If-Match", "*");
            conn.setRequestMethod("PUT");
        }
        else
        {
            conn.setRequestMethod("POST");
        }

        conn.setRequestProperty("GData-Version", "3.0");
        conn.setRequestProperty("User-Agent", "GPSLogger for Android");


        conn.setUseCaches(false);
        conn.setDoInput(true);
        conn.setDoOutput(true);

        DataOutputStream wr = new DataOutputStream(
                conn.getOutputStream());
        wr.writeBytes(fileContents);
        wr.flush();
        wr.close();

        int code = conn.getResponseCode();
        newLocation = conn.getHeaderField("location");

以上代码用于创建会话以获取可恢复 URL 以及将文件内容发布到可恢复 URL。

这是this Android 活动的一部分。我包括一个指向原始活动的链接,因为只需克隆存储库就可以很容易地重现问题。代码一年没有动过。

最近有什么变化会导致这种情况吗?

我想暂时避免使用 Google Drive 的 API,因为我没有更改任何代码,并且我在该领域的一些其他应用程序中使用了相同的代码。

【问题讨论】:

标签: java android google-docs-api


【解决方案1】:

最烦人的“功能”之一是请求图像时未记录的速率限制,每个请求都必须经过身份验证。速率限制似乎在 10/s 左右。

【讨论】:

    【解决方案2】:

    您可能正在使用目前已弃用的 Google API v2。阅读以下帖子:

    https://developers.google.com/google-apps/documents-list/terms
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-15
      相关资源
      最近更新 更多