user828061
user828061

Reputation: 91

google calendar sync token expire

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

Upvotes: 0

Views: 1862

Answers (1)

Brady Holt
Brady Holt

Reputation: 2934

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

Upvotes: 0

Related Questions