1

我正在使用 Google 日历 API 并遇到了这个问题:

谷歌日历 V3 插入

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.
4

1 回答 1

3

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

此外,在查看其他插入示例(可能不是日历)时,我注意到 API 可以采用 :body 属性,该属性可能(在您的情况下)包含实际的日历数据(即“摘要”)。在这里它实际上提到了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'})
于 2013-08-31T23:04:21.803 回答