简体   繁体   中英

Ruby on Rails Google API

I'm currently doing a Ruby on Rails project where I try to query from the Google Calendar API. I'm using this line of code:

service = Google::Apis::CalendarV3::CalendarService.new

and I have the gem google-api-client in my Gemfile. However, when I try to run the app with this line, it fails saying that it is Unknown Constant: Google Apis. If I try to put in the line that I've seen on StackOverflow, where I put require 'google/apis/calendar_v3' in the ruby file, it fails. I've spent 4 hours online trying to find anyone with a similar solution. If I try another API, like require 'google/apis/drive_v2' , it works fine, just calendar. :(

The following works for me on Rails 4.2.1 -- Note that there are two requires.

require 'google/apis'
=> true
require 'google/apis/calendar_v3'
=> true
service = Google::Apis::CalendarV3::CalendarService.new
=> #<Google::Apis::CalendarV3::CalendarService:0x007fca01ae60a0 @root_url="https://www.googleapis.com/", @base_path="calendar/v3/", @upload_path="upload/calendar/v3/", @batch_path="batch", @client_options=#<struct Google::Apis::ClientOptions application_name="unknown", application_version="0.0.0", proxy_url=nil, use_net_http=false>, @request_options=#<struct Google::Apis::RequestOptions authorization=nil, retries=0, header=nil, timeout_sec=nil, open_timeout_sec=20>>

My gem file contains:

gem 'google-api-client', '0.9'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM