【问题标题】:Ruby on Rails Google APIRuby on Rails Google API
【发布时间】:2016-11-03 03:34:15
【问题描述】:

我目前正在做一个 Ruby on Rails 项目,我尝试从 Google Calendar API 进行查询。我正在使用这行代码:

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

我的 Gemfile 中有 gem google-api-client。但是,当我尝试使用此行运行应用程序时,它无法说它是 Unknown Constant: Google APIs。如果我尝试放入我在 StackOverflow 上看到的行,我将 require 'google/apis/calendar_v3' 放入 ruby​​ 文件中,它会失败。我在网上花了 4 个小时试图找到有类似解决方案的人。如果我尝试其他 API,例如 require 'google/apis/drive_v2',它可以正常工作,只是日历。 :(

【问题讨论】:

  • 尝试参考这个网站,它对我有用。 thegreatcodeadventure.com/…
  • 您能否编辑您的问题以包含确切的错误消息?您称之为“未知常量”的那个,以及使用require“失败”的那个。

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


【解决方案1】:

以下在 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>>

我的 gem 文件包含:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多