Fusion Tables:在尝试通过Ruby的RestClient gem更新表格样式时,为什么我一直收到“400 Bad Request”错误

我正在尝试使用 Ruby gem RestClient更新我的一个Fusion Tables的样式.

这是我的代码

require 'rest_client'

tableId = '<STRING CONTAINING TABLEID>'
styleId = '<STRING CONTAINING STYLEID>'
key = '<STRING CONTAINING MY FUSION TABLES API KEY>'

table_url = "https://www.googleapis.com/fusiontables/v1/tables/#{tableId}/styles/#{styleId}?key=#{key}"
update = '{"polygonoptions": {"strokeColor":"#ffffff"}}'

token = 'STRING CONTAINING AUTHORIZATION TOKEN'

RestClient.put table_url,update,{"Authorization" => "Bearer #{token}"}

当我运行该代码时,我收到此错误

C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!': 400 Bad Request (RestClient::BadRequest)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
    from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient.rb:80:in `put'

当我将更新代码输入到Google’s official Style request PUT maker thingie时,更新有效.但是当我运行我的Ruby代码时它不起作用.

有谁知道我做错了什么?

编辑:我在RestClient.log = logger中添加的额外输出

RestClient.put "https://www.googleapis.com/fusiontables/v1/tables/<MY TABLE ID HERE>/styles/4?key=<AND HERE'S WHERE MY FUSION TABLE API KEY GOES>","{\"polygonoptions\":{\"strokeColor\":\"#ffffff\"}}","Accept"=>"*/*; q=0.5,application/xml","Accept-Encoding"=>"gzip,deflate","Authorization"=>"Bearer <THIS CONTAINS THE BEARER STRING>","Content-Length"=>"44"
# => 400 BadRequest | application/json 255 bytes

解决方法

你真的应该使用 google-api-ruby-client库而不是构建自己的REST调用.该库为您提取了大量OAuth内容和参数格式.

话虽如此,你可以enable debugging for your RestClient并发布RestClient调用输出以及谷歌官方PUT制造商的输出(我喜欢你的技术术语)吗?比较两者应该显示它们之间的差异以及Google与您的不同之处.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...