randomBrainstormer / MMM-GoogleCalendar

Google Calendar for MagicMirror²
MIT License
73 stars 46 forks source link

I am frequently running into invalid_grant issue which usually goes away with regenerating token ? Is there a way to fix this problem permanently? #10

Open randomBrainstormer opened 2 years ago

randomBrainstormer commented 2 years ago

hi @randomBrainstormer, I am frequently running into invalid_grant issue which usually goes away with regenerating token ? Is there a way to fix this problem permanently?

Originally posted by @letsandeepio in https://github.com/randomBrainstormer/MMM-GoogleCalendar/issues/9#issuecomment-1026131221

randomBrainstormer commented 2 years ago

hi @letsandeepio,

Unfortunately, we can't control the invalid_granterror, this is returned by google whenever they think there's an issue with the token, and this can be something as little as going offline for 1 second or asking for too many requests. Example of other reasons here.

Currently, I don't have a way to fix this problem permamently, as soon as I can figure something out I would definitely push it to the repo.

Some things to try out in the meantime is the fetchInterval option, setting it a higher interval (15 mins) can help lower the load.

randomBrainstormer commented 2 years ago

I've been thinking for a possible solution for this problem and got two ideas to explore:

  1. Google allows you to renew the token without the need of user input using the current credential type (TV and unlimited input). This could pontentially save us from getting invalid_grant so often.
  2. Try using a different type of credential (other than TV and Unlimited Input). This won't solve the invalid_grant issue directly, but rather force us to change the authorization flow and possibly integrate some kind of "Log in" feature in the module's UI. It would at least make the authorization process more simple.

I'll try to run some tests when I have some more free time

Raeymeister commented 2 years ago

hi randomBrainstormer, I love your module, but experience the same problem every 1 or 2 weeks.

The widget shows 'Error in the MMM-GoogleCalendar Module. Check logs for more details.' Then, I go to the module directory

'cd ~/MagicMirror/modules/MMM-GoogleCalendar/MMM-GoogleCalendar.js`

Remove the token.json

'rm token.json'

Regenerate the token and follow instructions by running

'node authorize.js'

To prevent doing this every week, I just implemented your suggested workaround of changing the fetchInterval value, I did it like this:

nano ~/MagicMirror/modules/MMM-GoogleCalendar/MMM-GoogleCalendar.js

changed value from: fetchInterval: 5 60 1000, to fetchInterval: 15 60 1000,

I hope it works.

Keep up the good work!

sidevesh commented 1 year ago

I figured out recently that by moving the Google app project to Production, this issue of invalid_grant requiring authorizing again every week or so, gets solved. Haven't had to reauthorize in a long time now.

Milkysunshine commented 1 year ago

I figured out recently that by moving the Google app project to Production, this issue of invalid_grant requiring authorizing again every week or so, gets solved. Haven't had to reauthorize in a long time now.

I know that was a while ago, but do you remember how you did that exactly? I don't know if it is because the coffee hasn't kicked in yet, but I'm not finding how to do that?

nobbie25 commented 11 months ago

@Milkysunshine You have to go google cloud console where you set up the magic mirror app. Once you get to your app find the OAuth consent screen. There is a publishing status where it will probably say Testing. If you push publish app you will move it to production. I would be very careful and read exactly what you are doing and ensure that you have your permissions set appropriately before you publish the app.