ruby-on-rails - 本地测试 Google API 客户端监视事件

标签 ruby-on-rails google-calendar-api google-api-client google-api-ruby-client

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

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

这是一个电话(为了清晰起见,进行了精简),以防我做了任何愚蠢的事情:

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 转发的推送通知。

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

兄弟, 伊森

关于ruby-on-rails - 本地测试 Google API 客户端监视事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32832177/

相关文章:

android - 存储访问 token ,Google+ 集成 Android 应用程序

android - 在玩家未登录时处理 Google Play 游戏成就

ruby-on-rails - 存储数据库中引用的常量的最佳方式?

ruby-on-rails - rails : Accessing JS module methods from files served by webpacker

android - 无法从公共(public)谷歌日历 api v3 获取事件

java - 解析谷歌日历时SAX解析异常

grails - Google Calendar API 事件地点

ruby - 使用 Ruby 授权 google drive api

ruby-on-rails - 注册时以嵌套形式传递 user_id 并保存两个模型

ruby-on-rails - 在 Rails 中更改连接表中的列名