2014-09-10 85 views
3

谷歌日历观看API方法的问题我与谷歌日历推送通知(或web_hook)一个问题 - 在Ruby on Rails的calendar.event.watch API方法。我正在使用gem“google-api-client”。然后在铁轨控制台尝试做:与回报率

require 'google/api_client' 
client = Google::APIClient.new 
client.authorization.access_token = "ya29.ewCcVb888OzntBusvtRcZsvfF7kOFMusnyjncR1-FJVr_oX79SgcOMbb" 
data = client.execute api_method: service.events.watch, parameters: { id: "my-unique-id-0001", type: "web_hook", calendarId: "primary", address: "https://mywebsite.com/notifications"} 

,并收到此错误:

#<Google::APIClient::Schema::Calendar::V3::Channel:0x3ffc15ebc944 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"required", "message"=>"entity.resource"}], "code"=>400, "message"=>"entity.resource"}}>> 

回答

0

当您在请求主体中发送,请确保它在JSON。

所以,如果你有一个哈希然后JSON-IFY它。

body_of_request = { id: "my_unique_id", type: web_hook, address: your_address } 
body_of_request.to_json 

此外请确保将请求标头中的内容类型设置为'application/json'。

3

因为我浪费在这个相当长的一段时间,觉得找出问题所在后相当愚蠢的,这里是正确回答这个问题的任何人都犯同样的错误。

的问题是要传递表中的数据执行方法的parameters选项。此选项用于添加到HTTP请求的URL和查询参数的参数。

但是,watch方法只能在查询URL中使用以下参数之一:calendarId(为了引用日历资源)。所有其他设置应该作为HTTP 请求主体中的JSON对象发送。因此

require 'google/api_client' 

client = Google::APIClient.new 
client.authorization.access_token = "ya29.ewCcVb888OzntBusvtRcZsvfF7kOFMusnyjncR1-FJVr_oX79SgcOMbb" 

data = client.execute api_method: service.events.watch, parameters: { 
    calendarId: "primary", 
}, body_object: { 
    id: "my-unique-id-0001", 
    type: "web_hook", 
    address: "https://mywebsite.com/notifications" 
} 

原来的问题的代码的正确形式是body_object选项串行传递的对象到JSON,并将其发送作为HTTP请求体,它是手表方法期望什么。

+0

我也面临着谷歌日历腕表问题。 http://stackoverflow.com/questions/34654504/calendar-events-notification-not-received-on-server – 2016-01-07 15:53:00