【问题标题】:authentication using rest_client, 401 unauthorized asana api使用 rest_client 进行身份验证,401 未经授权的 asana api
【发布时间】:2014-11-16 09:43:07
【问题描述】:

我正在尝试从 asana rest api 获得响应。但它返回给我 401 未经授权的错误。我正在使用下面的代码来获得响应:

    require 'base64'
    require 'rest_client'
    @user='mailid'
    @pass='YWlzNydXNoMTIz\n'
    @url="https://app.asana.com"
    response = RestClient::Request.new(
    :method => :get,
    :url => @url + "/" + "api/1.0/users/me",
    :user => @user,
    :password => Base64.decode64(@pass),

  ).execute
  @results = JSON.parse(response.to_str)
  p @results

我收到此错误 /.rvm/gems/ruby-2.1.0/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!': 401 Unauthorized (RestClient ::未经授权)

请说出这段代码的问题。

【问题讨论】:

    标签: ruby authentication automation rest-client asana


    【解决方案1】:

    可以使用 HTTP 基本身份验证,但您需要按照Developer Documentation 中的说明将 API 密钥作为用户名(而不是密码)传递。所以,它应该看起来像:

    @api_key='FcZ23.M4xsMtXmTKmDA4ssLCkEnYi'
    ...
    :user => @api_key,
    :password => ""
    

    您可以从您的帐户设置 > 应用程序 > API 密钥获取您的 API 密钥。

    【讨论】:

      猜你喜欢
      • 2017-08-18
      • 2018-07-09
      • 2016-09-09
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 2013-08-09
      • 2016-04-15
      • 2018-01-23
      相关资源
      最近更新 更多