google-api-clientでカレンダーを取得したいのですが、認証は成功しているものの、data.itemsが取得できません。
ruby 2.2.0
gem 'google-api-client', require: 'google/api_client'
以下のような実装で、実行しても、本日のカレンダーの一覧が取得できませんでした。
自分のカレンダーには確かに予定は入っております。
勿論issuerのところは正しい値を入れております。
class GoogleCalendarService
def self.today_events
cal = @client.discovered_api('calendar', 'v3')
@client.execute(
api_method: cal.events.list,
parameters: {
calendarId: 'primary',
orderBy: 'startTime',
timeMin: Time.current.beginning_of_day.iso8601,
timeMax: Time.current.end_of_day.iso8601,
singleEvents: 'True'
}
).data.items
end
def self.client
@client ||= Google::APIClient.new(application_name: '').tap do |client|
key = Google::APIClient::PKCS12.load_key('p12ファイルのパス', 'notasecret')
client.authorization = Signet::OAuth2::Client.new(
token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
audience: 'https://accounts.google.com/o/oauth2/token',
scope: 'https://www.googleapis.com/auth/calendar.readonly',
issuer: 'issuer@api-project-250641402888.iam.gserviceaccount.com',
signing_key: key
)
client.authorization.fetch_access_token!
end
end
end
デバッグをする中で、
cal
=> Google::APIClient::API:0x3ff89b41c6ec ID:calendar:v3
hoge = @client.execute(
api_method: cal.events.list,
parameters: {
calendarId: 'primary',
orderBy: 'startTime',
timeMin: Time.current.beginning_of_day.iso8601,
timeMax: Time.current.end_of_day.iso8601,
singleEvents: 'True'
}
)
hogeの返り値はGoogle::APIClient::Result:0x007ff13865fac8で、色々とデータが入っておりました。
hoge.data
Google::APIClient::Schema::Calendar::V3::Events:0x3ff89d345604 DATA:{"kind"=>"calendar#events", "etag"=>"\"1454212261000000\"", "summary"=>"issuer@api-project-250641402888.iam.gserviceaccount.com", "updated"=>"2016-01-31T03:51:01.000Z", "timeZone"=>"UTC", "accessRole"=>"owner", "defaultReminders"=>[], "items"=>[]}
hoge.data.items
[]
となってしまい、肝心なhoge.data.itemsの値は取得できませんでした。
ログを見ている限り、どこに原因があるのかがわからず、どうしたらいいのかわかりません。
どなたかアドバイスいただけないでしょうか?
宜しくお願いします。