简体   繁体   English

Ruby on Rails Google API

[英]Ruby on Rails Google API

I'm currently doing a Ruby on Rails project where I try to query from the Google Calendar API. 我目前正在做一个Ruby on Rails项目,尝试从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. 而且我的Gemfile中有gem google-api-client However, when I try to run the app with this line, it fails saying that it is Unknown Constant: Google Apis. 但是,当我尝试使用此行运行该应用程序时,无法说这是未知常量: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. 如果我尝试将我在StackOverflow上看到的行放在ruby文件中的require 'google/apis/calendar_v3'的地方,它将失败。 I've spent 4 hours online trying to find anyone with a similar solution. 我花了4个小时在网上尝试寻找具有类似解决方案的人。 If I try another API, like require 'google/apis/drive_v2' , it works fine, just calendar. 如果我尝试使用其他API,例如require 'google/apis/drive_v2' ,那么它可以正常工作,只是日历。 :( :(

The following works for me on Rails 4.2.1 -- Note that there are two requires. 以下在Rails 4.2.1上对我有用-请注意有两个要求。

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文件包含:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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