2016-07-14 80 views
0

我试图验证我的凤凰框架/ elixir后端twitter数字api ...当我使用curl它成功了,但我真的不知道如何使用HTTPotion生成它...我试过不同的组合,但总是返回“215”,“错误的验证数据”。Oauth echo使用elixir HTTPotion

这里是我的代码使用curl

curl --get 'https://api.digits.com/1.1/sdk/account.json' --header 'Authorization: OAuth oauth_signature="my-oauth-signature",oauth_nonce="my-oauty-nonce",oauth_timestamp="my-oauth-timestamp",oauth_consumer_key="my-oauth-consumer-key",oauth_token="my-oauth-token",oauth_version="1.0",oauth_signature_method="HMAC-SHA1"' -v 

时,这是迄今为止我尝试使用HTTPotion做,但仍然没有 运气

HTTPotion.get "https://api.digits.com/1.1/sdk/account.json", [headers: ["Authorization": "OAuth", "oauth_consumer_key": "my-oauth-consumer-key", "oauth_nonce": "my-oauth-nonce", "oauth_signature": "my-oauth-signature", "oauth_signature_method": "HMAC-SHA1", "oauth_timestamp": "my-oauth-timestamp", "oauth_token": "my-oauth-token", "oauth_version": "1.0"]] 

我搜索了几天,但没有发现任何东西......请有人帮助我..

回答

1

curl命令是只创建1 Authorized标题,而不是多个标题,如HTTPotion代码。

这应该工作:

HTTPotion.get("https://api.digits.com/1.1/sdk/account.json", 
       [headers: ["Authorization": ~s|OAuth oauth_signature="my-oauth-signature",oauth_nonce="my-oauty-nonce",oauth_timestamp="my-oauth-timestamp",oauth_consumer_key="my-oauth-consumer-key",oauth_token="my-oauth-token",oauth_version="1.0",oauth_signature_method="HMAC-SHA1"|]]) 
+0

谢谢@Dogbert非常快速回复我想你的代码,但得到这样的响应:'code' **(FunctionClauseError)匿名FN/1无功能的语句匹配的HTTPotion .process_arguments/3 (httpotion)lib/httpotion.ex:356:HTTPotion.process_arguments中的匿名fn(“授权”)/ 3 (elixir)lib/enum.ex:1088:Enum。“ - map/2-lists (httpotion)lib/httpotion.ex:356:HTTPotion.process_arguments/3 (httpotion)lib/httpotion.ex:356:HTTPotion.request/3'code' –

+0

糟糕,有一个错字。请尝试新的代码。 – Dogbert

+0

哇的作品像魅力....谢谢@Dogbert –