gpt4 book ai didi

ruby-on-rails - 发送通过 HTTParty 发送的帖子查询

转载 作者:数据小太阳 更新时间:2023-10-29 07:40:40 25 4
gpt4 key购买 nike

我正在使用带有 HTTParty 的 Buffer App API 尝试通过 /updates/create 添加帖子方法,但 API 似乎忽略了我的“文本”参数并抛出错误。如果我在命令行上通过 cURL 执行此操作,它会完美运行。这是我的代码:

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 位于 POST 正文中,而不是查询字符串中。尝试 :body 而不是 :query:

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

关于ruby-on-rails - 发送通过 HTTParty 发送的帖子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9310737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com