2013-11-15 185 views
1

我試圖從textit.in API請求,並使用我使用'httparty' gem身份驗證憑據

在我的控制器我有軌道4

顯示請求到視圖的結果:

def show 
    auth = 'b1363362f8777..etc' 
    @sms = HTTParty.get("https://api.textit.in/api/v1/sms.json", :headers => { "Authorization" => auth}) 
    end 

在與它讀取API的站點上的文檔:

「您必須驗證所有的呼叫通過在您的API令牌中包含一個Authorization標頭。出於安全原因,所有呼叫必須使用HTTPS進行。

您授權頭應該是這樣的:

授權:令牌YOUR_API_TOKEN_GOES_HERE」

然後在我看來,我有<%= @sms %>

,但我得到{"detail"=>"Authentication credentials were not provided."}

我怎麼能包括授權我的獲取請求中的標題?

回答

2

應該是:

@sms = HTTParty.get("https://api.textit.in/api/v1/sms.json", :headers => { "Authorization" => "Token #{auth}" }) 
相關問題