简体   繁体   English

获取已登录用户的所有日历的列表(Google日历API)

[英]Get list of all calendars of logged in user (Google calendar API)

I am trying to get all the calendars of the logged in user via oauth google. 我正在尝试通过oauth google获取已登录用户的所有日历。 As of now I can get all the events in the primary calendar but I also want to display all the public calendars of the user. 到目前为止,我可以在主日历中获取所有事件,但我也想显示用户的所有公共日历。

Tried everything but could not find any method to fetch calendars. 尝试了所有方法,但找不到任何方法来获取日历。 This is a ruby on rails 5 app I am working on. 这是我正在使用的Rails 5应用程序上的红宝石。

Code to fetch events of current month 获取当前月份事件的代码

response = client.execute(api_method: service.events.list,
            parameters: { 'calendarId' => 'primary',
              'timeMin': Time.now.beginning_of_month.iso8601,
              'showDeleted': false,
              'singleEvents': true,
              'maxResults': 10,
              'orderBy': 'startTime'},
                headers: { 'Content-Type' => 'application/json' })

I tried client.calendarList.list but it shows error "Undefined method calendarList" 我尝试了client.calendarList.list,但显示错误“ Undefined method calendarList”

Thanks for help in advance. 预先感谢您的帮助。

Okay So I have found the solution to this problem and want to share in case someone else comes across same problem. 好的,所以我已经找到了解决此问题的方法,并希望与他人分享,以防其他人遇到相同的问题。

Here is the code service = client.discovered_api('calendar' , 'v3') @response = client.execute(api_method: service.calendar_list.list, parameters: {'calendarId' => 'secondary'}, 'showDeleted': false, 'maxResults': 10, headers: { 'Content-Type' => 'application/json' }) 这是代码service = client.discovered_api('calendar' , 'v3') @response = client.execute(api_method: service.calendar_list.list, parameters: {'calendarId' => 'secondary'}, 'showDeleted': false, 'maxResults': 10, headers: { 'Content-Type' => 'application/json' })

The problem was that you would need to use calendar_list instead of calendarList. 问题是您将需要使用calendar_list而不是calendarList。

This was the reason it was throwing method not found error. 这就是它抛出方法未找到错误的原因。

Here is the code you will need to initiate google api client. 这是启动Google api客户端所需的代码。

client = Google::APIClient.new(:auto_refresh_token => true)
 client.authorization.access_token = oauth_token
 client.authorization.refresh_token = refresh_token
 client.authorization.client_id = ENV["GOOGLE_CLIENT_ID"]
 client.authorization.client_secret = ENV["GOOGLE_SECRET"]

 if client.authorization.refresh_token && client.authorization.expired?
     client.authorization.fetch_access_token!
 end

refresh_token and oauth_token will be obtained from google after successful oauth login. oauth登录成功后,将从Google获取refresh_token和oauth_token。

ENV["GOOGLE_CLIENT_ID"] put the client_id obtained from the google while creating app. ENV["GOOGLE_CLIENT_ID"]放置在创建应用程序时从Google获得的client_id。 ENV["GOOGLE_CLIENT_ID"] put the client secret. ENV["GOOGLE_CLIENT_ID"]设置客户端密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 React 用作前端时,如何在 Ruby API 中访问用户的 Google 日历? - How do I get access User's Google Calendar in my Ruby API when using it with React as a Frontend? 限制列表中的登录用户 - Restrict logged in user in list 使用 Google::Api::V3 将事件添加到另一个用户的日历 - Add Event to Calendar of another user using Google::Api::V3 omn​​iauth-google-oauth2也可以用于从Google日历API中获取日历信息吗? - can omniauth-google-oauth2 be used also to get calendar info back from the google calendar API? 如何使用 ruby 中的 Google Drive api 获取 Google Drive 上文件夹内所有文件的列表 - How to get list of all files inside a folder on Google Drive using Google Drive api in ruby 确定用户是否已退出Gmail / Google(使用或不使用Google API) - Finding out if User has logged out of Gmail/Google (with or without Google API) 尝试获取服务帐户以使用Google Calendar API,ruby,calendar.insert_event错误 - Trying to get a service account to work with google calendar API, ruby, calendar.insert_event error Google Calendar API V3 - 插入日历 - Google Calendar API V3 - Insert Calendar 我如何 go 特定用户 email 收件箱或谷歌日历和所有其他谷歌应用程序 - How can i go specific user email inbox or google calendar and all other google application Google Calendar Oauth2 API - Google Calendar Oauth2 API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM