加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Fusion Tables:在尝试通过Ruby的RestClient gem更新表格样式时,

发布时间:2020-12-16 21:39:12 所属栏目:百科 来源:网络整理
导读:我正在尝试使用 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 =
我正在尝试使用 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与您的不同之处.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读