L'invio di un messaggio di query inviate via HTTParty
-
26-10-2019 - |
Domanda
sto lavorando con l'API Buffer App con HTTParty per cercare di aggiungere messaggi tramite il / aggiornamenti / creare metodo, ma l'API sembra ignorare il mio parametro "testo" e getta su un errore. Se lo faccio tramite cURL sulla riga di comando funziona perfettamente. Ecco il mio codice:
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
E sto correndo il metodo come questo:
BufferApp.new('{access_token}', '{profile_id}').create('{Text}')
Ho aggiunto debug_output $stdout
alla classe e sembra essere distacco 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"
Ma ottengo un errore. Mi sto perdendo qualcosa?
Soluzione
I reviewed the API, and the updates expect the JSON to be in the POST body, not the query string. Try :body
instead of :query
:
def create(text)
BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow