httparty経由で送信された投稿クエリを送信します
-
26-10-2019 - |
質問
私はhttpartyとバッファーアプリ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
クラスに、それは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"
しかし、エラーが発生します。私は何かが足りませんか?
解決
レビューしました API, 、そして更新は、JSONがクエリ文字列ではなく、ポストボディにあることを期待しています。試す :body
それ以外の :query
:
def create(text)
BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
所属していません StackOverflow