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

use*_*730 6 ruby oauth put rest-client google-fusion-tables

我正在尝试使用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}"}
Run Code Online (Sandbox Code Playgroud)

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

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'
Run Code Online (Sandbox Code Playgroud)

当我将update代码输入到Google官方Style请求PUT制造商的东西时,更新有效.但是当我运行我的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
Run Code Online (Sandbox Code Playgroud)

Jay*_*Lee 4

您确实应该使用google-api-ruby-client库,而不是构建自己的 REST 调用。该库为您抽象了许多 OAuth 内容和参数格式。

话虽如此,您能否为您的 RestClient 启用调试并发布 RestClient 调用的输出以及 Google 官方 PUT 制造商 thingie 的输出(我喜欢您的技术术语)?比较两者应该可以看出它们有何不同以及谷歌不喜欢你的。