我使用ruby curb gem并尝试在代码中调用此api。但是,我不确定如何传递-u参数。
curl -X GET -H 'Accept: application/json' -u 111122223333: https://api.somesite.com/v1/apps/e876c39/users/activities?updated_since=20130925T120000Z
这是我到目前为止的代码,但如果没有-u选项,它就无法运行。我尝试将其添加为参数,但不起作用。
url = "https://api.somesite.com/v1/apps/e876c39/users/activities?updated_since=20130925T120000Z"
curl = Curl::Easy.new(url)
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.username = ENV['APP_ID'].to_s + ':'
result = curl.perform
答案 0 :(得分:0)
看起来您正在尝试将用户名和密码(使用:
分隔符)传递给username=
方法,但glancing at the docs看起来该方法用于设置仅用户名(不是一个大惊喜)。如果要使用冒号语法设置用户名和密码,看起来userpwd=
是您想要的方法:
easy.userpwd =
string =>串设置用户名/密码字符串,以用于后续
形式perform
的调用。提供的字符串应采用"username:password"
答案 1 :(得分:0)
我能够使用RestClient
执行此操作require 'rest_client'
response = RestClient::Resource.new "https://api.humanapi.co/v1/apps/#{ENV['CLIENT_ID']}/users/activities?updated_since=20130925T120000Z", "#{ENV['APP_ID']}:", ""
results = JSON.parse response.get