我在玩 Google 日历 API 时发现了这个:
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/