0

抱歉,如果这是关于 oauth 的菜鸟问题

我已经根据此处的示例使用 devise+doorkeeper 实现了 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

由于某种原因,在提供程序中看不到页面参数。有人能帮助我吗?

4

1 回答 1

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
于 2013-03-06T05:21:08.190 回答