Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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
Google日历V3 Ruby API插入事件_Ruby_Google Calendar Api_Google Api Ruby Client - Fatal编程技术网

Google日历V3 Ruby API插入事件

Google日历V3 Ruby API插入事件,ruby,google-calendar-api,google-api-ruby-client,Ruby,Google Calendar Api,Google Api Ruby Client,我使用的例子来自 然而,我得到了一个错误: wwtlf:~/workspace $ ruby test.rb /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:202:in `check_status': required: Missing end time. (Google::Apis::ClientError) from /usr/

我使用的例子来自

然而,我得到了一个错误:

wwtlf:~/workspace $ ruby test.rb 
/usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:202:in `check_status': required: Missing end time. (Google::Apis::ClientError)
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/api_command.rb:103:in `check_status'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:170:in `process_response'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:275:in `execute_once'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:107:in `block (2 levels) in execute'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:104:in `block in execute'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:96:in `execute'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/base_service.rb:267:in `execute_or_queue_command'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/generated/google/apis/calendar_v3/service.rb:1207:in `insert_event'
示例中的事件对象有什么问题? 我试图用dateTime代替date\u time,但错误是一样的

UPD: 最初的例子是:

event = Google::Apis::CalendarV3::Event.new{
  summary: 'Google I/O 2015',
  location: '800 Howard St., San Francisco, CA 94103',
  description: 'A chance to hear more about Google\'s developer products.',
  start: {
    date_time: '2015-05-28T09:00:00-07:00',
    time_zone: 'America/Los_Angeles',
  },
  end: {
    date_time: '2015-05-28T17:00:00-07:00',
    time_zone: 'America/Los_Angeles',
  },
  recurrence: [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  attendees: [
    {email: 'lpage@example.com'},
    {email: 'sbrin@example.com'},
  ],
  reminders: {
    use_default: false,
    overrides: [
      {method' => 'email', 'minutes: 24 * 60},
      {method' => 'popup', 'minutes: 10},
    ],
  },
}
显然,有很多语法错误。 错过“方法”=>“弹出窗口”,“分钟错过”:10

因此,我决定修改它:

event = Google::Apis::CalendarV3::Event.new{
  summary:'Google I/O 2015',
  location:'800 Howard St., San Francisco, CA 94103',
  description:'A chance to hear more about Google\'s developer products.',
  start: {
    date_time:'2015-05-28T09:00:00-07:00',
    time_zone:'America/Los_Angeles',
  },
  end: {
    date_time:'2015-05-28T17:00:00-07:00',
    time_zone:'America/Los_Angeles',
  },
  recurrence: [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  attendees: [
    {email: 'lpage@example.com'},
    {email: 'sbrin@example.com'},
  ],
  reminders: {
    use_default: false,
    overrides: [
      {'method' => 'email', 'minutes'=> 24 * 60},
      {'method' => 'popup', 'minutes'=> 10},
    ],
  }
}

但是,我仍然得到了http_命令。rb:202:in‘check_status’:必需:缺少结束时间。Google::API::ClientError

我解决了我的问题。事件哈希必须如下所示:

event = Google::Apis::CalendarV3::Event.new({
  'summary':'Google I/O 2015',
  'location':'800 Howard St., San Francisco, CA 94103',
  'description':'A chance to hear more about Google\'s developer products.',
  'start':{
    'date_time': DateTime.parse('2016-05-28T09:00:00-07:00'),
    'time_zone': 'America/Los_Angeles'
  },
  'end':{
    'date_time': DateTime.parse('2016-05-28T17:00:00-07:00'),
    'time_zone': 'America/Los_Angeles'
  }
})

另外,别忘了通过json文件中的severice Accarun电子邮件提供对日历的访问。客户电子邮件:bla@blablabla.iam.gserviceaccount.com,我解决了我的问题。事件哈希必须如下所示:

event = Google::Apis::CalendarV3::Event.new({
  'summary':'Google I/O 2015',
  'location':'800 Howard St., San Francisco, CA 94103',
  'description':'A chance to hear more about Google\'s developer products.',
  'start':{
    'date_time': DateTime.parse('2016-05-28T09:00:00-07:00'),
    'time_zone': 'America/Los_Angeles'
  },
  'end':{
    'date_time': DateTime.parse('2016-05-28T17:00:00-07:00'),
    'time_zone': 'America/Los_Angeles'
  }
})

另外,别忘了通过json文件中的severice Accarun电子邮件提供对日历的访问。客户电子邮件:bla@blablabla.iam.gserviceaccount.com,

在您的示例中,您创建的ruby块等于:

Google::Apis::CalendarV3::Event.new do
  # something
end
但您想要的是传递如下哈希:

Google::Apis::CalendarV3::Event.new({
  key: value
})

在您的示例中,您创建的ruby块等于:

Google::Apis::CalendarV3::Event.new do
  # something
end
但您想要的是传递如下哈希:

Google::Apis::CalendarV3::Event.new({
  key: value
})

对我来说,atm使用以下语法:

Google::Apis::CalendarV3::Event.new({
  :summary => 'event title',
  :location => 'event address',
  :description => 'event description',
  :start => {
    :date_time => 'event start time in rfc3339'
  },
  :end => {
    :date_time => 'event end time in rfc 3339'
  }
})

对我来说,atm使用以下语法:

Google::Apis::CalendarV3::Event.new({
  :summary => 'event title',
  :location => 'event address',
  :description => 'event description',
  :start => {
    :date_time => 'event start time in rfc3339'
  },
  :end => {
    :date_time => 'event end time in rfc 3339'
  }
})
在提醒工作中:提醒方法

下面的例子

{   
    :summary=>"Never underestimate yourself!",                                                     
    :location=>"In my brain",
    :description=>"Never underestimate\nwhat you can acomplish\nwhen you believe in yourself.\n\nNever give up.\n\nhttp://www.youtube.com/watch?v=qX9FSZJu448",
    :attendees => [                                                                                
        {:email =>'Sample.Mail@gmail.com'},                                                        
    ],                                                                                             
    :start=>{                                                                                      
        :date_time=>"2019-05-12T11:30:00+02:00",                                                   
        :time_zone=>"Europe/Warsaw"                                                                
    },                                                                                             
    :end=>{                                                                                        
        :date_time=>"2019-05-12T11:30:15+02:00",                                                   
        :time_zone=>"Europe/Warsaw"
    },                                                              
    :reminders=>{                                                                                  
        :use_default=>false,                                                                       
        :overrides=>[                                                                              
            {:reminder_method=>"email", :minutes=>35}                                              
            {:reminder_method=>"popup", :minutes=>5}                                               
        ]                                                                                          
    }                                                                                              
}    
在提醒工作中:提醒方法

下面的例子

{   
    :summary=>"Never underestimate yourself!",                                                     
    :location=>"In my brain",
    :description=>"Never underestimate\nwhat you can acomplish\nwhen you believe in yourself.\n\nNever give up.\n\nhttp://www.youtube.com/watch?v=qX9FSZJu448",
    :attendees => [                                                                                
        {:email =>'Sample.Mail@gmail.com'},                                                        
    ],                                                                                             
    :start=>{                                                                                      
        :date_time=>"2019-05-12T11:30:00+02:00",                                                   
        :time_zone=>"Europe/Warsaw"                                                                
    },                                                                                             
    :end=>{                                                                                        
        :date_time=>"2019-05-12T11:30:15+02:00",                                                   
        :time_zone=>"Europe/Warsaw"
    },                                                              
    :reminders=>{                                                                                  
        :use_default=>false,                                                                       
        :overrides=>[                                                                              
            {:reminder_method=>"email", :minutes=>35}                                              
            {:reminder_method=>"popup", :minutes=>5}                                               
        ]                                                                                          
    }                                                                                              
}    

您是否可以尝试在这里查看并粘贴实际http请求是什么,以及其中事件的JSON主体是什么?免责声明-不是ruby开发人员。由于某种原因,无法识别最终对象。我看到您的代码片段与类似,除了一些被删除的属性之外,我看到的唯一不同之处是最后一个属性end,而不是像其他对象一样以结尾。如果检查其他对象,它们看起来像以逗号结尾,你能测试一下吗?你可以把“解决方案”从问题主体移到一个真正的答案上——在这里回答自己的问题是可以的。你能试着看看并粘贴在这里实际的http请求是什么,事件的JSON主体是什么吗?免责声明-不是ruby开发。出于某种原因,最终对象没有被识别。我看到您的代码片段与类似,除了一些被删除的属性之外,我看到的唯一不同之处是最后一个属性end,而不是像其他对象一样以结尾。如果你检查其他对象,它们看起来像是以逗号结尾的,你能测试一下吗?你可以把“解决方案”从问题主体移到真正的答案上——这样回答自己的问题就可以了。你是对的。实际上,这就是谷歌的例子。如您所见,我添加了括号,并通过将哈希作为agrument传递来调用构造函数new。您是对的。实际上,这就是谷歌的例子。如您所见,我添加了括号,并通过将哈希作为agrument传递来调用构造函数new。