2016-07-14 83 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 –