0

hi i am trying to sync google calendar with my local calendar

my current setup works like this

i login via google and get my primary calendar events and store locally and i also save the sync token google provide at the last page.

so i have created a channel to watch calendar and it sends me notifications each time there is a change in calendar but what i want is to get the changed data if i send request again it just says token is expired how can i work around this.

i am using ruby on rails and google api gem

thank you

user828061
  • 91
  • 1
  • 6
  • Are you getting 410 error when you use the sync token? if "yes" then the client should clear its storage and perform a full synchronization without any syncToken. Here is the link https://developers.google.com/google-apps/calendar/v3/sync – SGC Feb 24 '15 at 18:59
  • Notifications only tell you that there was a change. For retrieving the changed data, you need to use the sync token you got at the last events.list() request. – luc Mar 20 '15 at 23:23

1 Answers1

0

Access tokens expire. You need to save the refresh token after authorization is first granted so that you can ask for new access tokens when making requests to the API. I wrote a detailed blog post about it here: http://www.geekytidbits.com/google-calendar-api-from-ruby/

For example:

#First time authorization
auth_client.code = "authorization code goes here"
auth_client.fetch_access_token!
#Save auth_client.refresh_token now!

#Subsequent requests
auth_client.refresh_token = #grab refresh token from where you saved it
auth_client.fetch_access_token!
#You should now have a fresh access token
Brady Holt
  • 2,844
  • 1
  • 28
  • 34