如何使用和实例变量和HTTParty发布到使用OAuth2的API

时间:2012-09-27 23:11:00

标签: ruby oauth-2.0 httparty

我可以通过以下方式从Oauth2 API获取信息:

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

我如何发布在我的应用中生成的API内容?我有一个实例变量:

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

我试过了:

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

无济于事。

1 个答案:

答案 0 :(得分:11)

回答了我自己的问题

HTTParty.post("API Website", :headers => { "Authorization" => auth}, :body => "@contact")