简体   繁体   English

发送通过HTTParty发送的帖子查询

[英]Sending a post query sent via HTTParty

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. 我正在使用带有HTTParty的Buffer App API尝试通过/ updates / create方法添加帖子,但是API似乎忽略了我的“text”参数并引发了错误。 If I do it via cURL on the command line it works perfectly. 如果我在命令行上通过cURL这样做,它可以很好地工作。 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

And I'm running the method like this: 我正在运行这样的方法:

BufferApp.new('{access_token}', '{profile_id}').create('{Text}')

I've added debug_output $stdout to the class and it seems to be posting OK: 我已经将debug_output $stdout添加到了类中,它似乎正在发布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? 我错过了什么吗?

I reviewed the API , and the updates expect the JSON to be in the POST body, not the query string. 我查看了API ,并且更新期望JSON位于POST主体中,而不是查询字符串。 Try :body instead of :query : 尝试:body而不是:query

    def create(text)
        BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
    end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM