How can I post with an instance variable and HTTParty to an API that uses OAuth2

StackOverflow https://stackoverflow.com/questions/12631372

  •  04-07-2021
  •  | 
  •  

Вопрос

I can get information from an Oauth2 API by:

token = "Token I get from authenticating my App"
auth = "Bearer " + token
user = HTTParty.get("API Website", :headers => { "Authorization" => auth})

How would I post to that API content generated in my app? I have an instance variable:

@contact = {"contact": {"name": "John Doe"  }}

I tried this:

token = "Token I get from authenticating my App"
auth = "Bearer " + token
user = HTTParty.get("API Website", :headers => { "Authorization" => auth}, @contact)

to no avail.

Это было полезно?

Решение

Answered my own question

HTTParty.post("API Website", :headers => { "Authorization" => auth}, :body => "@contact")
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top