发送通过httparty发送的帖子查询
-
26-10-2019 - |
题
我正在使用HTTPARTY的Buffer App API,以尝试通过 /更新/创建 方法,但是API似乎忽略了我的“文本”参数并引发错误。如果我通过命令行上的卷发进行操作,则可以完美地工作。这是我的代码:
class BufferApp
include HTTParty
base_uri 'https://api.bufferapp.com/1'
def initialize(token, id)
@token = token
@id = id
end
def create(text)
BufferApp.post('/updates/create.json', :query => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
end
我正在运行这样的方法:
BufferApp.new('{access_token}', '{profile_id}').create('{Text}')
我已经添加 debug_output $stdout
在课堂上,它似乎在发布正常:
POST /1/updates/create.json?text=Hello%20there%20why%20is%20this%20not%20working%3F&profile_ids[]={profile_id}&access_token={access_token} HTTP/1.1\r\nConnection: close\r\nHost: api.bufferapp.com\r\n\r\n"
但是我有一个错误。我缺少什么吗?
解决方案
我回顾了 API, ,更新期望JSON在邮局中,而不是查询字符串。尝试 :body
代替 :query
:
def create(text)
BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
不隶属于 StackOverflow