【问题标题】:OLA API integration in Ruby on Rails web API {"code":"invalid_partner_key","message":"Partner key is not authorized"}Ruby on Rails Web API 中的 OLA API 集成 {"code":"invalid_partner_key","message":"Partner key is not authorized"}
【发布时间】:2016-10-03 21:25:32
【问题描述】:

我正在传递在 HTTParty 中使用 x 应用令牌调用 OLA API 所需的基本 URL,但它给出了以下错误:

{"code":"invalid_partner_key","message":"Partner key is not authorized"}

代码如下:

require 'rubygems'
require 'httparty'

class ProductsController < ApplicationController
  def index
    lat = params[:lat].to_s
    long = params[:long].to_s

    @results = HTTParty.get("https://api.uber.com/v1/products?server_token=my_token&latitude="+lat+"&longitude="+long).parsed_response
    @result1 = HTTParty.get("https://devapi.olacabs.com/v1/products?X-APP-TOKEN=my_token&pickup_lat=12.9491416&pickup_lng=77.64298").parsed_response

    respond_to do |format|
      format.json { render :json => JSON.parse(@results) }
      format.json { render :json => JSON.parse(@result1) }
      format.html { render "index.html.erb" }
    end
  end
end

为什么会发生这种情况,我该如何解决?

【问题讨论】:

    标签: ruby-on-rails api access-token httparty


    【解决方案1】:

    通过 olacabs 文档,您的 X-APP-TOKEN 应该作为标头而不是与有效负载一起传递。所以你应该做这样的事情

    query = { 
      "pickup_lat" => 12.9491416,
      "pickup_lng" => 77.64298
    }
    
    headers = { 
      "X-APP-TOKEN" => your_token
    }
    
    @result1 = HTTParty.get(
      "https://devapi.olacabs.com/v1/products", 
      :query => query,
      :headers => headers
    ).parsed_response
    

    我没有对此进行测试,但应该为解决您的问题提供一个良好的开端。

    【讨论】:

    • 还是不行。再次出现同样的错误:{"code":"invalid_partner_key","message":"Partner key is not authorized"}
    • 您是否将令牌作为字符串传递? "your_token"
    猜你喜欢
    • 2017-06-16
    • 2021-05-27
    • 2020-10-25
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 2020-12-31
    • 2022-01-28
    • 1970-01-01
    相关资源
    最近更新 更多