我正在尝试观看谷歌日历活动。
我写了这段代码:
def watch_calendar_event
result = @client.execute(
api_method: @calendar_api.events.watch,
parameters: { calendarId: 'primary' },
body_object: watch_hash,
headers: {'Content-Type' => 'application/json'}
)
if result.status == 200
watch_data = result.data
@calendar.update booking_expiration: watch_data.expiration, booking_id: watch_data.id, booking_resource_id: watch_data.resourceId, booking_resource_uri: watch_data.resourceUri, watching_event: true
end
rescue Exception => ex
raise GoogleCalendarException, ex.message
end
我正在获得200条成功消息,其中包含booking_id,resource_id和resourceUri等其他详细信息。
但是当我在Google日历上创建新活动时,我的服务器上没有收到任何通知。
任何想法可能是什么原因。
另请注意,我已完成了他们提出的所有问题here,并且我还为此配置了https服务器。
我的webhook网址如下:https://dev.application.com/notifications&我也为此开了路线。
我的路线:
post '/notifications', to: "calendars#calendar_events_watch", defaults: {format: 'json'}
我的控制器代码:
def calendar_events_watch
logger.info "Received an event notification. **************************#{request.env.inspect}"
if request.env["HTTP_X_GOOG_RESOURCE_STATE"] != "sync"
channel_id = request.env["HTTP_X_GOOG_CHANNEL_ID"]
resource_id = request.env["HTTP_X_GOOG_RESOURCE_ID"]
# resource_uri = request.env["HTTP_X_GOOG_RESOURCE_URI"]
# channel_token = request.env["HTTP_X_GOOG_CHANNEL_TOKEN"]
end
render status: 200
end