Google カレンダーのイベントリストをユーザーの認証時に取得して
データベースに保存したいと考えています。
下記のQiita記事を参考にして、google apiのドキュメントを読みながら進めているのですが
原因不明のエラーが発生してしまい困っています。
参考にしているQiita:https://qiita.com/yosidadada/items/083a05c8e4465baee98e
Signet::AuthorizationError Authorization failed. Server message: { "error": "unsupported_grant_type", "error_description": "Invalid grant_type: " }
エラーが出ているFetch Calendar Service
のソースコード
class FetchCalendarService CLIENT_OPTIONS = { client_id: Rails.application.credentials.google[:google_client_id], client_secret: Rails.application.credentials.google[:google_client_secret], authorization_uri: 'https://accounts.google.com/o/oauth2/auth', token_credential_uri: 'https://www.googleapis.com/oauth2/v4/token', scope: Google::Apis::CalendarV3::AUTH_CALENDAR, # redirect_uri: Rails.application.routes.url_helpers.google_auth_callback_url, additional_parameters: {prompt:'consent'}, } def initialize(user) @user = user end def fetch_event client = Signet::OAuth2::Client.new(CLIENT_OPTIONS) # client.update!(user.google_api_token) calendar = Google::Apis::CalendarV3::CalendarService.new service.authorization = client # List all calendar events now = Time.now.iso8601 items = calendar.fetch_all do |token| calendar.list_events('primary', single_events: true, order_by: 'startTime', time_min: now, page_token: token) end items.each { |event| puts event.summary } #store items.each do |event| calendar_event.start_at = event.start.dateTime calendar_event.end_at = event.end.dateTime calendar_event.summary = event.summary calendar_event.user_id = current_user return calendar_event end end end
client_update
とredirect
はエラーになってしまったのでコメントアウトしています。
どうやら、calendar.list_events
でエラー担っているので、イベントを取得するだけに十分な認証情報が取れていないということなのでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。