【问题标题】:Authentication credentials were not provided未提供身份验证凭据
【发布时间】:2013-11-15 17:44:02
【问题描述】:

我正在尝试从 textit.in API 请求并使用 rails 4 将请求结果显示到视图

我正在使用'httparty' gem

在我的控制器中,我有:

  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."}

如何在我的 get 请求中包含 Authorization 标头?

【问题讨论】:

    标签: ruby-on-rails ruby get ruby-on-rails-4 httparty


    【解决方案1】:

    应该是:

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

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 2020-07-22
      • 2021-11-29
      • 2019-04-26
      • 2020-01-11
      • 2019-07-29
      • 2019-06-11
      • 2019-05-25
      • 2021-12-21
      相关资源
      最近更新 更多