ruby-on-rails - 缺少必需的客户标识符 - Google 日历
问题描述
我正在按照本教程在我的 Rails 应用程序上实现谷歌日历。 https://readysteadycode.com/howto-integrate-google-calendar-with-rails
配置/初始化程序/omiauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2,
ENV['my_long_key'],
ENV['my_other_key'],
{ scope: "userinfo.email, calendar" }
end
我还生成了 config/secrest.yml(它不存在):
secret_key_base: "i_generated_a_string"
google_client_id: "my_long_key"
google_client_secret: "my_other_long_key"
控制器/example_controller.rb
class ExampleController < ApplicationController
before_action :authenticate_candidate!, except: [:redirect]
before_action :authenticate_interviewer!, except: [:client_options]
def redirect
client = Signet::OAuth2::Client.new(client_options)
redirect_to client.authorization_uri.to_s
end
private
def client_options
{
client_id: ENV["google_client_id"],
client_secret: ENV["google_client_secret"],
authorization_uri: "https://accounts.google.com/o/oauth2/auth",
token_credential_uri: "https://accounts.google.com/o/oauth2/token",
scope: Google::Apis::CalendarV3::AUTH_CALENDAR,
redirect_uri: callback_url
}
end
end
宝石
gem 'google-api-client', require: 'google/apis/calendar_v3'
gem 'omniauth-google-oauth2'
gem 'signet', '~> 0.11.0'
然而
当我去:http://localhost:3000/redirect
我得到:Missing required client identifier.
解决方案
很可能带有您的 google 凭据的 env 变量不会传递给进程(ENV["google_client_id"]
也可能是其他进程)
推荐阅读
- java - 是系统范围内的通用 ForkJoin 池还是每个 JVM 实例
- matlab - 在x轴上重叠第二组数据python-顺序未保留
- c++ - 如何在 Windows 上紧密打包结构?
- mergesort - 为什么右子数组MergeSort的中间
- loops - 如何访问 BufReader 两次?
- python - 使用 send_file 返回多个图像
- mysql - 在当前值上使用 where 子句的更新语句
- javascript - 无法调用 Blazor javascript 方法
- javascript - Angular 从 API 获取 JSON 对象并将其存储在变量中,检查是否存在
- python - 无法从 Python 中的字符串中去除引号