簡體   English   中英

將curl命令轉換為httparty

[英]Translating a curl command to httparty

我想從Rails應用程序中使用一些API數據。 一個卷曲的例子是curl --data 'api_key=your_api_key&api_secret=your_api_secret&host_id=your_user_host_id' https://api.zoom.us/v1/webinar/list我在終端進行了實驗,我看到了預期的回復。 我現在正在使用httparty嘗試使用ruby腳本。 我的問題是如何在端點之前處理'stuff'(api_key ... secret ... ect)? 這些標題是?

關於curl --data只告訴我這是一個帖子請求,但我不確定這是如何轉換為httparty。

這是第一次嘗試:

require 'httparty'

api_key = 'myKey'
api_secret = 'secret'
host_id = 'host'
data_type = 'JSON'

response = HTTParty.post("api_key&api_secret&host_id&data_type https://api.zoom.us/v1/webinar/list/registration")

puts response.parsed_response

但這給了我一個糟糕的URI響應。 如果我只使用端點運行相同的腳本,我會從縮放中獲得一個響應代碼,說明需要API密鑰和密鑰。

看看這個例子,我認為這應該有效:

require 'httparty'

api_key = 'myKey'
api_secret = 'secret'
host_id = 'host'
data_type = 'JSON'

options = {
  body: {
    api_key: api_key,
    api_secret: api_secret,
    host_id: host_id,
    data_type: data_type
  }
}
response = HTTParty.post("https://api.zoom.us/v1/webinar/list/registration", options)

puts response.parsed_response

我收到了回復:

{“error”=> {“code”=> 200,“message”=>“無效的api密鑰或密碼。”}}

我認為這是朝着正確方向邁出的一步。

沒有那些不是標題那些是參數。 標頭通常由-H標志去除。

試試這個:

require 'httparty'

query_params = {api_key: 'myKey',
                api_secret: 'secret',
                host_id: 'host',
                data_type: 'JSON'}

response = HTTParty.post("api_key&api_secret&host_id&data_type https://api.zoom.us/v1/webinar/list/registration", :query => query_params)

puts response.parsed_response

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM