googleAPIでアプリからスプレッドシートを編集できる機能を実装しようとしています。
在はローカル上で開発しています。
リダイレクトURLにアプリ内のパスをを登録しても必ずhttp://localhost:3000/oauth2callback
へのリダイレクトになってしまい、
Error: redirect_uri_mismatch The redirect URI in the request, http://localhost:3000/oauth2callback, does not match the ones authorized for the OAuth client.
というエラーが表示され、想定どおり動きません。
GCP上では以下のようにURLを設定していますが、このURLにリダイレクトさせたいです。
コントローラーは以下のような処理になっています。
module GoogleApi module Sheets class SheetsController < GoogleController require 'google/apis/sheets_v4' require 'googleauth' require 'googleauth/stores/file_token_store' require 'fileutils' before_action :authorize OOB_URI = "http://localhost:3000/google_api/sheets/callback/" APPLICATION_NAME =************** CREDENTIALS_PATH = ************** TOKEN_PATH = 'token.yaml' SCOPE = Google::Apis::SheetsV4::AUTH_SPREADSHEETS def authorize client_id = Google::Auth::ClientId.from_file(CREDENTIALS_PATH) token_store = Google::Auth::Stores::FileTokenStore.new(file: TOKEN_PATH) authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store) user_id = 'default' credentials = authorizer.get_credentials(user_id) credentials if credentials.nil? url = authorizer.get_authorization_url(base_url: OOB_URI) redirect_to url end credentials end def callback code = params[:code] credentials = authorizer.get_and_store_credentials_from_code( user_id: user_id, code: code, base_url: OOB_URI ) credentials end end end end
設定の方法など間違っていますでしょうか。
お詳しい方いらっしゃいましたら、アドバイス頂けますと幸いです。
何卒宜しくお願いいたします。
あなたの回答
tips
プレビュー