ArgumentError - 间隔不是有效选项 - Rails中的Google Calendar API错误

时间:2017-05-01 16:11:34

标签: ruby-on-rails ruby google-api google-calendar-api

我一直在尝试解决Google的Calendar API与我的rails应用程序的集成问题,但似乎无法弄清楚出了什么问题。我用谷歌搜索了所有地方,但没有找到任何提到这个特殊错误。

错误是:

ArgumentError - interval is not a valid option
retriable (3.0.2) lib/retriable/config.rb:32:in `block in initialize'
retriable (3.0.2) lib/retriable/config.rb:31:in `initialize'
retriable (3.0.2) lib/retriable.rb:18:in `retriable'
google-api-client (0.7.1) lib/google/api_client.rb:595:in `execute!'
google-api-client (0.7.1) lib/google/api_client.rb:330:in `discovery_document'
google-api-client (0.7.1) lib/google/api_client.rb:375:in `discovered_api'
app/services/google_calendar_api.rb:41:in `new_api_session'
app/services/google_calendar_api.rb:11:in `create_event'
app/controllers/events_controller.rb:57:in `create'

在这一行提出:

@service = @client.discovered_api('event', 'v3')

这是我用来初始化api会话的代码:

# This is in my google_api.rb

class GoogleCalendarAPI

  def initialize(user, params, event)
    @user = user
    @params = params
    @event = event
    @client = User.find_by(id: params[:user_id])
  end

  def create_event
    if new_api_session
      create_event_object_using_params
      send_google_event_create_request
      update_google_event_id_on_event
    end
  end

private 

def new_api_session
  if @user.access_token?
    @client = Google::APIClient.new
    @client.authorization.access_token  = @user.access_token
    @client.authorization.refresh_token = @user.refresh_token
    @client.authorization.client_id     = ENV['GOOGLE_CLIENT_ID']
    @client.authorization.client_secret = ENV['GOOGLE_CLIENT_SECRET']
    @client.authorization.grant_type    = 'refresh_token'
    @client.authorization.refresh!
    @service = @client.discovered_api('event', 'v3')
  else
    return
  end
end

# Events crontroller
def create
  @event = Event.new(event_params)
  if (event_params[:user_id]).blank?
    @event.user_id = current_user.id
  end

  if params[:send_client_email].present?
    ClientMailer.event_creation_notification(event_params, @event, params, current_user).deliver_now
  end

  # If the user authorized their Google Calendar create the event
  # in their Google Calendar using the API
  if current_user.access_token?
    google_api_session = GoogleCalendarAPI.new(current_user, event_params, @event)
    google_api_session.create_event
  end

  respond_to do |format|
    if @event.save
      format.html { redirect_to events_path , notice: 'Event was successfully created.' }
      format.json { render :show, status: :created, location: @event }
    else
      format.html { render :new }
      format.json { render json: @event.errors, status: :unprocessable_entity }
    end
  end
end       

我正在使用以下宝石:

gem 'omniauth-google-oauth2'
gem 'google-api-client', '~0.7.1', require: 'google/api_client'    

我能够成功获取用户的access_token和refresh_token以及provider和uid,但由于某种原因无法初始化API会话。

如果您需要任何其他信息,请提前告知我们,并提前感谢任何指导或想法!

1 个答案:

答案 0 :(得分:1)

尝试在您的Gemfile中将可重复版本绑定到3.0.1:

gem 'retriable', '3.0.1'