LoginSignup
10
12

More than 5 years have passed since last update.

google-api-ruby-clientを用いて、Google Calendarにアクセスしてイベントを取得する

Posted at

バージョン

  • google-api-ruby-client: 0.9.pre3

事前に必要なもの

  • Google Developers ConsoleでクライアントID、クライアントシークレットを取得して、Google Calendar APIを有効にしておく
  • 何かしらの方法でリフレッシュトークンを取得しておく
  • 取得したいカレンダーのカレンダーIDを用意する
require 'google/api_client/client_secrets'
require 'google/apis/calendar_v3'

client        = Google::Apis::CalendarV3::CalendarService.new
authorization = Google::APIClient::ClientSecrets.new(
  'web' => {
    client_id:     [クライアントID],
    client_secret: [クライアントシークレット],
    refresh_token: [リフレッシュトークン]
  }
).to_authorization
client.authorization = authorization

events = client.list_events([カレンダーID])

試してないので断言できませんが、Google Calendar以外の場合も似たような方法でAPIにアクセスできると思います。

10
12
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
10
12