3

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クラスに追加しましたが、投稿は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"

しかし、エラーが発生します。何か不足していますか?

4

1 に答える 1

19

APIを確認しましたが、更新では、クエリ文字列ではなく、JSON が POST 本文にあることが想定されています。:body代わりに試してください:query

    def create(text)
        BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
    end
于 2012-02-16T13:27:56.777 に答える