いつも大変お世話になっております。
Ruby on RailsでGoogle認証したユーザーのカレンダー情報を半年分取得できるような仕様を実装したいと考えています。ユーザー登録したときに、これを実行できればと考えているのですが、下記のエラーが出てしまい実行できません。
uninitialized constant SessionsController::Google
ユーザーはGoogle認証で取ってきていますが、deviseは使っていません。
カレンダーは、ユーザーと1対多で紐付く形で格納していきたいと考えています。
下記のサイトを参考に作りました。
https://qiita.com/PharaohKJ/items/ba2a226a2c8173c4bb41
まず、Google api clientが正常に動いていないと考え
こちらの記事を参考に再度goggle client api のgemをインストールして入れ直してみたのですが、やはりうまくいっていません。
開発環境
Mac
'rails', '> 5.2.1'> 0.11'
'google-api-client', '
'omniauth-google-oauth2'
ソースコード
/config/omniauth.rb
Ruby
1Rails.application.config.middleware.use OmniAuth::Builder do 2 provider :google_oauth2, 3 Rails.application.credentials.google[:google_client_id], 4 Rails.application.credentials.google[:google_client_secret], 5 { 6 :provider_ignores_state => true, 7 image_size: 150, 8 scope: %w(https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/calendar).join(' '), 9 prompt: 'consent', 10 access_type: 'offline' 11 } 12end
app/controllers/sessions_controller.rb
Ruby
1class SessionsController < ApplicationController 2・・・ 3 def create 4 @user = User.from_omniauth(request.env["omniauth.auth"]) 5 secrets = Google::APIClient::ClientSecrets.new( 6 web: { 7 access_token: @user.credentials.token, 8 refresh_token: @user.credentials.refresh_token, 9 client_id: Rails.application.credentials.google[:google_client_id], 10 client_secret: Rails.application.credentials.google[:google_client_secret] 11 } 12 ) 13 14 cal_service = Google::Apis::CalendarV3::CalendarService.new 15 cal_service.authorization = secrets.to_authorization 16 @calendar_list = cal_service.list_calendar_lists 17 18 if @user.save 19 session[:user_id] = @user.id 20 render json: @calendar_list 21 else 22 render json: "fail to login.\n", status: 500 23 end 24 end 25・・・
Googleカレンダーを取得してくるアクションをメソッド化して、別のパターンでも取ってこれるようにするのが理想です。
欲しい情報は、各イベントの「開始日時」、「終了日時」のみです。すみませんが、おたすけくださいませ。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/09 05:16