4

I'm writing a program that uses the google calendar api, so I used the quick start from here and it worked. but recently the same code stopped working and gave me the following error.

The API returned an error: Error: invalid_grant

This means that the error came from

103: calendar.events.list()

What could cause this problem and how can I fix it?

nloomans
  • 220
  • 2
  • 11
  • Are you getting invalid_grant error when using refresh token? If that is the case, check this link https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization. It could probably due to server's clock not in sync with NTP or refresh token limit has exceeded. – SGC Oct 08 '15 at 16:55
  • i had a service account working for months and I started getting invalid_grant a couple of days ago... – chevett Oct 09 '15 at 15:43

1 Answers1

5

This happened to me when I changed my account password. To fix it I had to delete the credentials file that gets referenced in the quick start here:

var SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'];
TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||
process.env.USERPROFILE) + '/.credentials/';
var TOKEN_PATH = TOKEN_DIR + 'drive-nodejs-quickstart.json';

This should do the trick.

rm /Users/<username>/.credentials/drive-nodejs-quickstart.json
Jeremy Irish
  • 51
  • 1
  • 2
  • Just 1 google search result for this problem but, boom! the correct solution. Thanks! :-) – drodsou Apr 21 '17 at 23:02
  • Thank you! Stating the obvious: you need to adjust the name of the credentials file depending on which quickstart you're using. For example: youtube-nodejs-quickstart.json. – Sam Dutton Mar 18 '19 at 14:54