5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RubyからGoogleカレンダーを使う

Posted at

手順

GoogleConsoleからアプリ追加

Gemfileに設定を追加

Gemfile
gem 'omniauth-google-oauth2'
gem 'google-api-client', '~> 0.10'
gem 'signet'

認証してアクセストークン、リフレッシュトークンを取得

Googleカレンダーのイベントを取得

require 'signet/oauth_2/client'
require 'google/apis/calendar_v3'

client = Signet::OAuth2::Client.new(
  client_id: 'クライアントID',
  client_secret: 'クライアントシークレット',
  access_token: 'アクセストークン',
  refresh_token: 'リフレッシュトークン',
  token_credential_uri: 'https://accounts.google.com/o/oauth2/token'
)
client.refresh!

service = Google::Apis::CalendarV3::CalendarService.new
service.authorization = client

events = service.list_events('primary')
5
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?