用于Google文档的Google API,请求文档列表-400错误请求 [英] Google API for Google Docs, requesting a list of documents -- 400 Bad Request

查看:112
本文介绍了用于Google文档的Google API,请求文档列表-400错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Google服务器对Google文档进行身份验证后,我做了一个简单的getResponse,但收到了400错误的请求.我不明白我要去哪里错了.示例代码在下面

After authentication from google servers for google docs, I do a simple getResponse, but I get a 400 Bad Request. I can't understand where am I going wrong. The sample code is, below

  private void executeRefreshAlbums() {
        HttpRequest request = transport.buildGetRequest();
        request.url = GoogleDocsUrl.forDefaultPrivateFull();
        System.out.println("URL = "+request.url);
        try {
            HttpResponse response = request.execute();
            System.out.println("Response = "+response.getContent());

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

  }

sysout将正确的网址打印为

The sysout prints the correct url as

03-12 17:36:59.573: INFO/System.out(451): URL = https://docs.google.com/feeds/default/private/full

但是当我这样做时,我会得到

But When I do this, I get

03-12 17:43:41.360: WARN/System.err(3958): com.google.api.client.http.HttpResponseException: 400 Bad Request
03-12 17:43:41.415: WARN/System.err(3958):     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:209)
03-12 17:43:41.415: WARN/System.err(3958):     at com.example.Test.executeRefreshAlbums(Test.java:198)
03-12 17:43:41.415: WARN/System.err(3958):     at com.example.Test.authenticated(Test.java:190)
03-12 17:43:41.415: WARN/System.err(3958):     at com.example.Test.authenticatedClientLogin(Test.java:156)
03-12 17:43:41.415: WARN/System.err(3958):     at com.example.Test.access$1(Test.java:153)
03-12 17:43:41.415: WARN/System.err(3958):     at com.example.Test$2$1.run(Test.java:139)
03-12 17:43:41.415: WARN/System.err(3958):     at android.os.Handler.handleCallback(Handler.java:587)
03-12 17:43:41.415: WARN/System.err(3958):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-12 17:43:41.415: WARN/System.err(3958):     at android.os.Looper.loop(Looper.java:123)
03-12 17:43:41.415: WARN/System.err(3958):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-12 17:43:41.415: WARN/System.err(3958):     at java.lang.reflect.Method.invokeNative(Native Method)
03-12 17:43:41.415: WARN/System.err(3958):     at java.lang.reflect.Method.invoke(Method.java:521)
03-12 17:43:41.422: WARN/System.err(3958):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-12 17:43:41.422: WARN/System.err(3958):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-12 17:43:41.422: WARN/System.err(3958):     at dalvik.system.NativeStart.main(Native Method)

任何帮助将不胜感激.我已经尝试了一个小时了:-(

Any help would be really appreciated. I have been trying it for an hour now :-(

推荐答案

在另一个线程用户@Merlin上

At the other thread user @Merlin provided the solution which solved similar issue. His solution was to specify the API version number 3.0 in the request as stated in the "Google Documents List Data API" document:

重要:如果您向仅使用功能的API发出请求 在版本3中可用,但是忘记设置版本,您将 可能会收到 400错误的请求响应.由于URL结构是 在版本2和版本3之间有所不同,这是由 API的新用户.

Important: If you make a request to the API that uses a feature only available in version 3, but forget to set the version, you will most likely receive a 400 Bad Request response. Since the URL structure is different between versions 2 and 3, this is a common mistake made by new users of the API.

要指定版本号,请使用 GData-Version HTTP标头.该标头的值必须为 3.0 .这 十进制和零是必需的.

To specify a version number, use the GData-Version HTTP header. The value of this header must be 3.0. The decimal and the zero are required.

  GData-Version: 3.0

 GData-Version: 3.0

或者, 您可以在URL中将 v=3 指定为查询参数.这经常 在剥离HTTP标头的防火墙后工作时需要的,或者 来自一些JavaScript请求.建议使用HTTP标头 若有可能.

Alternatively, you can specify v=3 as a query parameter in the URL. This is often needed when working behind a firewall that strips HTTP headers, or from some JavaScript requests. Use of the HTTP header is recommended when possible.

  https://docs.google.com/feeds/default/private/full?v = 3

这篇关于用于Google文档的Google API,请求文档列表-400错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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