设计门卫oauth2 API分页

时间:2013-03-04 07:40:22

标签: api devise oauth-2.0 doorkeeper

很抱歉,如果这是关于oauth的noob问题

我已根据以下示例使用设计+门卫实施了oauth2 API:https://doorkeeper-provider.herokuapp.com/此处:https://github.com/applicake/doorkeeper-devise-client

我希望能够提供一个API端点,该端点返回可分页的交易列表,代码如下:

module Api::V1
  class DealsController < ApiController
    doorkeeper_for :index
    doorkeeper_for :create, :scopes => [:write]

    respond_to :json

    def index
      if params[:page].nil?
        page = 1
      else
        page = params[:page].to_i
      end
      respond_with Deal.page(page).order("published DESC")
    end

    def create
      respond_with 'api_v1', Deal.create!(params[:deal])
    end
  end
end

但是,在客户端,我无法通过以下内容传递页面参数:     /explore/deals.json?page=3

由于某种原因,提供程序中未显示页面参数。有人能帮帮我吗?

1 个答案:

答案 0 :(得分:1)

我意识到问题出在了doorkeeper-devise-client

的api_controller中

页面参数未正确传递。进行以下更改可以解决问题:

class ApiController < ApplicationController
  respond_to :json

  def explore
    api_call = params[:api]
    if !params[:page].nil?
      api_call << "/?page=#{params[:page]}"  
    end

    @json = doorkeeper_access_token.get("api/v1/#{api_call}").parsed
    respond_with @json
  end
end
相关问题