L'envoi d'une requête via HTTParty Message envoyé
-
26-10-2019 - |
Question
Je travaille avec l'API App tampon avec HTTParty pour essayer d'ajouter les messages via le / mises à jour / créer méthode, mais l'API semble ignorer mon paramètre « texte » et vomit une erreur. Si je le fais via cURL sur la ligne de commande, il fonctionne parfaitement. Voici mon code:
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
Je suis en cours d'exécution de la méthode comme ceci:
BufferApp.new('{access_token}', '{profile_id}').create('{Text}')
J'ai ajouté debug_output $stdout
à la classe et il semble afficherons 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"
Mais je reçois une erreur. Suis-je de quelque chose qui manque?
La solution
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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow