加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 01:52:26 所属栏目:百科 来源:网络整理
导读:我正在使用带有HTTParty的Buffer App API来尝试通过 /updates/create方法添加帖子,但是API似乎忽略了我的“text”参数并引发了错误.如果我在命令行上通过cURL这样做,它可以很好地工作.这是我的代码: class BufferApp include HTTParty base_uri 'https://ap
我正在使用带有HTTParty的Buffer App API来尝试通过 /updates/create方法添加帖子,但是API似乎忽略了我的“text”参数并引发了错误.如果我在命令行上通过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添加到了类中,它似乎正在发布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.1rnConnection: closernHost: api.bufferapp.comrnrn"

但是我收到了一个错误.我错过了什么吗?

解决方法

我查看了 API,并且更新期望JSON位于POST主体中,而不是查询字符串.尝试:body而不是:query:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读