0

I ran a test run to learn how to connect to google calendar api via node.google auth with node js

I re-walked through the steps to attempt to connect my actual project to google calendar api, but when i run node quickstart.js i get this error:

The API returned an error: Error: unauthorized_client

after hours of deliberating I figured out that the Google client library was saving my auth info on my disk. So, when i ran node quickstart.js, I received an error because my new client_secret.json that I created for my actual project, did not match the info in my client_secret.json that was created in my test run.

A doc suggestion that I found that i think is relevant:

// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/calendar-nodejs-quickstart.json

but when I navigate to my user folder I do not have a .credentials directory, thus I'm unable to locate and delete my old auth info.

I tried searching for oauth via global search and found a few oauth.js files that I thought were the issue. I naively deleted all of them and then re ran the command only to find the terminal yell at me for not having an oauth node module.

After more hours of replacing the oauth files I deleted I'm still unable to locate or delete the troublesome auth info.

Has anyone encountered a similar problem while programming on a mac and connecting to Google API thru node?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
alex glaze
  • 53
  • 10
  • Check your project directory for the credentials. Or even your quickstart program, as the path to save credentials can be specified during the auth process. – tehhowch Mar 27 '18 at 05:28

2 Answers2

0

Assuming your code is following the quick start. You can find the credeitlals for the user

var TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||    process.env.USERPROFILE) + '/.credentials/';

If you change it to (or the equivalent to a mac directory structure not mac person sorry)

var TOKEN_DIR = c:\currentdir\credentials;

It should request access again and store the new credentials file there

Note:

It looks like the way the code works they are expecting you to have the .json file in that directory. So remember to put it in what ever directory you have TOKEN_DIR set to.

var TOKEN_PATH = TOKEN_DIR + 'calendar-nodejs-quickstart.json';
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 1
    The problem I had was finding that credentials directory. I learned that it was a hidden folder and learned how to show / hide hidden folders. For any future problem havers the answer is to navigate to /Users/YOURUSERPROFILE in finder and pressing: CMD + SHIFT + . to show the hidden credential folder – alex glaze Mar 27 '18 at 17:01
  • @alexglaze your answer is the valid answer my friend. post it as answer and accept it – ReyAnthonyRenacia Oct 17 '20 at 10:17
0

The problem I had was finding that credentials directory. I learned that it was a hidden folder and learned how to show / hide hidden folders. For any future problem havers the answer is to navigate to /Users/YOURUSERPROFILE in finder and pressing: CMD + SHIFT + . to show the hidden credential folder

alex glaze
  • 53
  • 10