Google API for Google Docs,请求文档列表 – 400 Bad Request

从谷歌服务器validation谷歌文档后,我做了一个简单的getResponse,但我收到400错误请求。 我不明白我哪里错了。 示例代码如下

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打印正确的URL作为

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

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

 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) 

任何帮助将非常感激。 我现在已经尝试了一个小时:-(

在另一个线程用户@Merlin 提供了解决类似问题的解决方案。 他的解决方案是在请求中指定API版本号3.0,如“ Google文档列表数据API ”文档中所述:

重要提示 :如果您向使用仅在版本3中提供的function的API发出请求,但忘记设置版本,则很可能会收到400 Bad Request响应 。 由于版本2和版本3之间的URL结构不同,这是API的新用户常犯的错误。

要指定版本号,请使用GData-Version HTTP标头。 此标头的值必须为3.0 。 小数和零是必需的。

GData-Version: 3.0

或者,您可以在URL中指定v=3作为查询参数。 在阻止HTTP标头或某些JavaScript请求的防火墙后面工作时,通常需要这样做。 建议尽可能使用HTTP标头。

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

不确定您使用的transport对象是什么;

这是一个简单的HttpGet请求:

  HttpGet getMethod = new HttpGet(URI); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 30000); HttpConnectionParams.setSoTimeout(params, 30000); DefaultHttpClient httpClient = new DefaultHttpClient(params); HttpResponse response = httpClient.execute(getMethod); BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String returnString = ""; String line = ""; do { returnString += line; line = in.readLine(); } while (line != null); 

也许使用这种方法会得到一个更明显的错误?