谷歌文档API上传文件时,会返回一个503服务不可用。有事改变了吗? [英] Google Docs API returns a 503 Service Unavailable when uploading a file. Has something changed?

查看:827
本文介绍了谷歌文档API上传文件时,会返回一个503服务不可用。有事改变了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有应用程序,利用谷歌文档的API。直到最近,使用HTTP端点上传一直工作正常。近日,已上载突然开始示数。第一次调用创建一个会话(返回可恢复URL)工作正常,并返回一个可恢复的URL。试图然后将文件发送内容到可恢复URL抛出一个503。

I have applications that make use of the Google Docs API. Up until recently, uploads using the HTTP endpoints has been working fine. Recently, uploading has suddenly started erroring. The first call to create a session (which returns the resumable URL) works fine, and returns a resumable URL. Attempting to then send the file contents to the resumable URL throws a 503.

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

The relevant part of the code throwing the error is this:

        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");

以上code是创建会话,以获得可恢复URL以及发布文件的内容会可恢复URL中使用这两种。

The above code is used both for creating the session to get the resumable URL as well as posting file contents to the resumable URL.

这是<一部分href="https://github.com/mendhak/googledocs-upload-sample/blob/master/src/com/mendhak/example/PureJavaUploadActivity.java">this Android的活动。我包括一个链接到原来的活动,因为它很可能会很容易通过简单的克隆库重现该问题。在code一年一直保持不变。

Which is part of this Android activity. I am including a link to the original activity as it would probably be quite easy to reproduce the problem by simply cloning the repository. The code has remained untouched for a year.

最近,有件事改变,将导致此?

Has something changed recently that would cause this?

我想避免使用谷歌驱动器的API的现在,因为我并没有改变任何code和相同的code是我的一些该领域的其他应用中使用。

I would like to avoid having to use Google Drive's APIs for now as I have not changed any code and the same code is being used in a few of my other applications in the field.

推荐答案

您可以使用谷歌API V2是pcated截至目前德$ P $。阅读后下:

You may be using Google API v2 which is deprecated as of now. Read the below post:

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

这篇关于谷歌文档API上传文件时,会返回一个503服务不可用。有事改变了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆