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

前端之家收集整理的这篇文章主要介绍了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与您的不同之处.

原文链接:https://www.f2er.com/ruby/267145.html

猜你在找的Ruby相关文章