草庐IT

java - Google Docs 的 Google API,请求文档列表 -- 400 Bad Request

coder 2023-12-16 原文

从谷歌服务器对谷歌文档进行身份验证后,我执行了一个简单的 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 provided解决类似问题的解决方案。他的解决方案是在请求中指定 API 版本号 3.0,如“Google Documents List Data 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.

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

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

关于java - Google Docs 的 Google API,请求文档列表 -- 400 Bad Request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5286400/

有关java - Google Docs 的 Google API,请求文档列表 -- 400 Bad Request的更多相关文章

  1. ruby - RVM 使用列表[0] - 2

    是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论

  2. ruby-on-rails - Rails HTML 请求渲染 JSON - 2

    在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这

  3. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  4. jquery - 我的 jquery AJAX POST 请求无需发送 Authenticity Token (Rails) - 2

    rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送

  5. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  6. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  7. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  8. Matlab imread()读到了什么 (浅显 当复习文档了) - 2

    matlab打开matlab,用最简单的imread方法读取一个图像clcclearimg_h=imread('hua.jpg');返回一个数组(矩阵),往往是a*b*cunit8类型解释一下这个三维数组的意思,行数、数和层数,unit8:指数据类型,无符号八位整形,可理解为0~2^8的数三个层数分别代表RGB三个通道图像rgb最常用的是24-位实现方法,即RGB每个通道有256色阶(2^8)。基于这样的24-位RGB模型的色彩空间可以表现256×256×256≈1670万色当imshow传入了一个二维数组,它将以灰度方式绘制;可以把图像拆分为rgb三层,可以以灰度的方式观察它figure(1

  9. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  10. 【Java 面试合集】HashMap中为什么引入红黑树,而不是AVL树呢 - 2

    HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候

随机推荐