如何获得有效的client_id,response_type和redirect_uri参数instagram rails

时间:2017-11-21 23:06:38

标签: ruby-on-rails api rubygems instagram

我正在使用oauth2设计并尝试使用instagram登录。但是,当我登录时,它给了我这个错误:

You must include a valid client_id, response_type, and redirect_uri parameters

我已将客户端ID放在我的application.yml文件中,但它无法正常工作

instagram.rb

Instagram.configure do |config|
  config.client_id = ENV['CLIENT_ID']
  config.client_secret = ENV['CLIENT_SECRET']
end

callbacks_controller.rb

class CallbacksController < Devise::OmniauthCallbacksController
  def instagram
    @user = User.from_omniauth(request.env["omniauth.auth"])
    sign_in_and_redirect @user
  end
end

application.yml

CLIENT_ID : "221ea35dc7c1489c946e2f3062e8984a"
CLIENT_SECRET: "e8a100e6f1d44842a26f6bf7c4c5a063"
REDIRECT_URI : "http://localhost:3000/users/auth/instagram/callback"

的routes.rb

Rails.application.routes.draw do  devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
  root 'products#index'
end

user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,         :recoverable, :rememberable, :trackable, :validatable,     :omniauthable, :omniauth_providers => [:instagram]

  def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.password = Devise.friendly_token[0,20]
    end  
  end

  ...

end

0 个答案:

没有答案