在 rails 中使用 Google+ 签名时出错

error in Sign with Google+ in rails

我正在尝试使用 google 或 rails 中的任何其他社交网络实现登录。我已经通过 http://r12---sn-cvh7kn7y.googlevideo.com/videoplayback?sparams=dur,ei,expire,id,i

关注了 Codeplace 教程

我遇到了以下问题

 Error: invalid_request

Missing required parameter: client_id

Learn more

 Request Details
  access_type=offline
 scope=email profile
response_type=code
redirect_uri=http://localhost:9292/auth/google_oauth2/callback
state=2f6a1b1d2e0a2fb1c75647a6d145efa907c3ee9038a8bb54
client_id=

我的相关代码是 - omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2,ENV['238730796202-.com'],ENV['TyqJqfiOJLoLgqRRGgTIynxt']
 provider :facebook, ENV['1585034338471672'],ENV['3211b382a1636bdc747d37921aab2a90']
 end

sessioncontroller.rb

 class SessionsController < ApplicationController

def create
    auth = request.env["omniauth.auth"]
    puts auth
    session[:omniauth] = auth.except('extra')
    user = User.sign_in_from_omniouth(auth)
    session[:user_id] = user_id
    redirect_to root_url, notice:"Sign In"
end
def destroy
    session[:user_id] = nil
    session[:omniauth] = nil
    redirect_to root_url, notice:"Sign OUT"
end
end

user.rb

   class User < ActiveRecord::Base
    def self.sign_in_from_omniouth(auth)
    find_by(provider: auth['provider'], uid: auth['uid'])||   
    create_user_from_omniauth(auth)
end

   def self.create_user_from_omniauth(auth)
      create(
    provider:auth['provider'],
    uid:auth['uid'],
    name:auth['info']['name']

    )
end
end
end

谁能帮帮我?

根据遇到的错误,缺少 client_id

尝试 documentation 中给出的基本步骤,其中通过执行以下操作从 Google API 控制台获取 OAuth 2.0 凭据:

Visit the Google API Console to obtain OAuth 2.0 credentials such as a client ID and client secret that are known to both Google and your application.

也请尝试通过 GoogleAPI 控制台。如本 GitHub post 中所述,如果未启用这些,您将收到 OAuth2::Error(Error: "Invalid credentials") 说明在您尝试进行身份验证时未配置访问权限。

请尝试浏览给定的 GitHub post、OmniAuth Google OAuth2 Strategy 以获得重要的详细信息。