本地测试 Google API 客户端观察事件

Locally testing Google API Client watch events

我正在使用 google api ruby client 将 webhook 添加到日历,但我 运行 进入了 Google::Apis::ClientError: pushWebhookBadDomain

我已经设置了一个 ngrok 实例并在网站管理员工具上对其进行了验证,以便我可以将其作为允许的域添加到处理所有日历身份验证等的项目中。我找不到任何对此的引用特定错误,所以我想知道使用 ngrok 是否有什么奇怪的地方,以及是否有更好的方法来在本地测试 webhooks。

这是电话(为清楚起见进行了压缩),以防我做任何愚蠢的事情:

require 'google/apis/calendar_v3'
client = Google::Apis::CalendarV3::CalendarService.new
authorization = Signet::OAuth2::Client.new(
  :authorization_uri =>
    'https://accounts.google.com/o/oauth2/auth',
  :token_credential_uri =>
    'https://accounts.google.com/o/oauth2/token'
)
authorization.client_id = ENV['GOOGLE_CLIENT_ID']
authorization.client_secret = ENV['GOOGLE_CLIENT_SECRET']
authorization.grant_type = 'refresh_token'
authorization.refresh_token = refresh_token
authorization.fetch_access_token!
client.authorization = authorization

channel = Google::Apis::CalendarV3::Channel.new(address: success_callback_url, id: channel_id, type: "web_hook")
binding.pry
webhook = client.watch_event('primary', channel, single_events: true, time_min: Time.now.iso8601)

当您在 AppEngine 项目的 Google Cloud Console 中将域注册为允许域时,您不应在域名前包含 https://。您需要将其注册为 xxxxxxx.ngrok.io.

我遇到了与您相同的问题,在添加允许域时删除 https:// 后,我能够在本地计算机上接收使用 ngrok 转发的推送通知。

如果对你有帮助,请告诉我。

Br, 伊桑