Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 谷歌日历API V3-插入日历_Ruby On Rails_Ruby_Json_Calendar_Google Calendar Api - Fatal编程技术网

Ruby on rails 谷歌日历API V3-插入日历

Ruby on rails 谷歌日历API V3-插入日历,ruby-on-rails,ruby,json,calendar,google-calendar-api,Ruby On Rails,Ruby,Json,Calendar,Google Calendar Api,我在玩谷歌日历API时遇到了以下问题: Ruby代码似乎不是Ruby代码,所以我从calendar_列表和calendar中移植了信息。开始吧。我不知道为什么参数摘要没有被作为标题 def create @auth = request.env["omniauth.auth"] @token = @auth["credentials"]["token"] client = Google::APIClient.new client.authorization.acces

我在玩谷歌日历API时遇到了以下问题:

Ruby代码似乎不是Ruby代码,所以我从calendar_列表和calendar中移植了信息。开始吧。我不知道为什么参数摘要没有被作为标题

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尝试过GoogleAPI,但是从你的错误和文章的内容来看,我相信总结就是标题(正如你所说的)

另外,在查看其他(可能不是日历)时,我注意到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'})

谢谢你,亚瑟。对于其他人,我将参数设置为{},并执行JSON.dump('summary'=>'testname'),这在我的gcal上生成了一个测试名称日历