How do I use the Google Calendar API client library for Ruby to get a list of calendar IDs for only my account? -
i'm trying create web application takes data google calendar account , puts on website uses own calendar program. don't want have user permission account every time run program, since user of account, , according https://developers.google.com/api-client-library/ruby/auth/service-accounts , https://developers.google.com/identity/protocols/oauth2, seems way use service account. ideal option scenario? @ rate, set service account, generated json file credentials, , attempted create code return list of calendar ids can access of calendars:
require 'google/apis/calendar_v3' require 'googleauth' require 'oauth' cert_path = gem.loaded_specs['google-api-client'].full_gem_path+'/lib/cacerts.pem' env['ssl_cert_file'] = cert_path env['google_application_credentials'] = 'c:\users\eric\desktop\tripleseat project\my project-6006a5b60113.json' def createserviceobject() service = google::apis::calendarv3::calendarservice.new scope = ["https://www.googleapis.com/auth/calendar"] service.authorization = google::auth.get_application_default(scope) service.authorization.fetch_access_token! return service end service = createserviceobject() response = service.list_calendar_lists() puts response puts response.items
this code not run errors when run command prompt, , response api. however, response.items field turns out empty though google calendar account lists multiple calendars under "my calendars" menu on left side of screen, , each calendar has multiple events associated it. i'm guessing problem service account not associated google calendar account. however, cannot find documentation explains how associate service account single google account. there bunch of information how using google apps domain, google app engine, or google compute engine can let access accounts of multiple users, don't want use of these things relatively simple ruby program (i'm not using rails or sinatra). rather host program on heroku server, have other similar programs set up. there other reasons why api response turn empty? should api returning @ if doesn't know account data from?
i figured out problem was. needed go google calendars account , change settings of calendar give permission share information service account. had click gear icon in upper right corner of google calendar page, go settings, go calendars, click shared:edit settings, enter e-mail address service account, , set permission settings 1 of make changes options on dropdown menu.
Comments
Post a Comment