发送通过HTTParty发送的帖子查询 [英] Sending a post query sent via HTTParty
问题描述
我正在使用带有HTTParty的Buffer App API尝试通过添加帖子/ updates / create 方法,但是API似乎忽略了我的 text参数,并引发了错误。如果我通过命令行上的cURL做到这一点,则效果很好。这是我的代码:
I'm working with the Buffer App API with HTTParty to try and add posts via the /updates/create method, but the API seems to ignore my "text" parameter and throws up an error. If I do it via cURL on the command line it works perfectly. Here's my code:
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
到班级,并且似乎发布了OK:
I've added debug_output $stdout
to the class and it seems to be posting OK:
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"
但是我得到一个错误。我是否缺少任何东西?
But I get an error. Am I missing anything?
推荐答案
我查看了 API ,并且更新期望JSON位于POST正文中,而不是查询字符串中。尝试使用:body
代替:query
:
I reviewed the API, and the updates expect the JSON to be in the POST body, not the query string. Try :body
instead of :query
:
def create(text)
BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
这篇关于发送通过HTTParty发送的帖子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!