首页 > 解决方案 > 缺少必需的客户标识符 - 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.

错误

标签: ruby-on-rails

解决方案


很可能带有您的 google 凭据的 env 变量不会传递给进程(ENV["google_client_id"]也可能是其他进程)


推荐阅读