Reputation: 95
I've been trying to troubleshoot the integration of Google's Calendar API with my rails app but can't seem to figure out what's wrong. I've Googled all over the place but couldn't find any mentions of this particular error.
The error is:
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'
It's raised at this line:
@service = @client.discovered_api('event', 'v3')
This is the code I'm using to initialize the api session:
# 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
I'm using the following gems:
gem 'omniauth-google-oauth2'
gem 'google-api-client', '~0.7.1', require: 'google/api_client'
I am able to successfully get the user's access_token and refresh_token as well as provider and uid but for some reason can't initialize the API session.
Let me know if you need any other info and thanks in advance for any guidance or ideas!
Upvotes: 2
Views: 830
Reputation: 2884
Try to bind retriable version to 3.0.1 in your Gemfile:
gem 'retriable', '3.0.1'
Upvotes: 1