ruby-on-rails - Google Calendar API V3 - 插入日历

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

我在玩 Google 日历 API 时发现了这个:

Google Calendar V3 Insert

Ruby 代码似乎不是 Ruby 代码,所以我将 calendar_list 和 calendar.get 中的信息移植到这里。我不确定为什么参数摘要没有被选为标题。

def create      
  @auth = request.env["omniauth.auth"]
  @token = @auth["credentials"]["token"]
  client = Google::APIClient.new
  client.authorization.access_token = @token
  service = client.discovered_api('calendar', 'v3')
  @result = client.execute(
    :api_method => service.calendars.insert,
    :parameters => {"summary" => 'Calendar Title'},
    :headers => {'Content-Type' => 'application/json'})
end

导致错误

--- !ruby/object:Google::APIClient::Schema::Calendar::V3::Calendar
data:
  error:
    errors:
    - domain: global
      reason: required
      message: Missing title.
    code: 400
    message: Missing title.

最佳答案

老实说,我还没有尝试过使用 ruby​​ 的 google api,但是在查看你的错误和 google documentation 时我相信摘要等于标题(如您所述)。

另外,在看其他examples of inserts (也许不是日历)我注意到 API 可以采用 :body 属性,它可能(在您的情况下)包含实际的日历数据(即“摘要”)。和 here它实际上在 tryit 下提到了请求“body”。

再说一次,我还没有尝试过这个,但我会尝试以下操作:

  @result = client.execute(
    :api_method => service.calendars.insert,
    :parameters => # not sure what parameters the insert needs,
    :body => JSON.dump(cal), # where cal is the object containing at least "summary".
    :headers => {'Content-Type' => 'application/json'})

关于ruby-on-rails - Google Calendar API V3 - 插入日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18552272/

相关文章:

javascript - Angular JS 提取 JSON 数据

ruby-on-rails - 如何获取列表中具有相同类别的所有项目

ruby-on-rails - Rails 教程第 7.4.4 章 Git 之后所有测试都失败

ios - Meteor 网络应用程序可以向 iOS 应用程序提供数据吗?

ruby-on-rails - Rails/ruby 未定义的方法

ruby - Chef Recipe 中的无效多字节字符 (US-ASCII)

javascript - 如何让 jQuery AJAX 将 .map 函数 var 值作为 JSON 字符串发布

ruby-on-rails - 在一个模型上创建多个条目 - Ruby on Rails(非嵌套)

ruby-on-rails - rake 中止! UTF-8 中的无效字节序列

ruby-on-rails - 如何在 Rails 5 中创建 ActiveRecord 无表模型?