PhanthomD
PhanthomD

Reputation: 23

How to fix Google Calendar API error

I following https://developers.google.com/google-apps/calendar/quickstart/nodejs#step_3_set_up_the_sample

But it not worked and output below this:

  var clientSecret = credentials.installed.client_secret;
                                          ^

TypeError: Cannot read property 'client_secret' of undefined
    at authorize (/Users/prangyy/myApp/quickstart.js:32:43)
    at processClientSecrets (/Users/prangyy/myApp/quickstart.js:21:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)

Upvotes: 2

Views: 1072

Answers (3)

JMess
JMess

Reputation: 39

No need to modify the original code if you check 'Other' (as said in the tutorial) when you choose your Application type in the client ID creation page (step 4 of your pasted text)

Upvotes: 1

krithix
krithix

Reputation: 41

Change lines 34-36 in quickstart.js to:

var clientSecret = credentials.web.client_secret; 
var clientId = credentials.web.client_id; 
var redirectUrl = credentials.web.redirect_uris[0];

(There's an error where they've used credentials.installed instead of credentials.web, which is what shows up in the client_secrets.json file.)

Upvotes: 4

Mr.Rebot
Mr.Rebot

Reputation: 6791

Try checking your client_secret.json in the Node.js Quickstart.

It should contain clientID, auth_url, token_uri, auth_provider_x509_cert_url, client_secret, redirect_uris, javascript_origins.

{"web":{"client_id":"YOUR_CLIENT_ID","project_id":"google.com:my-project-1231","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"YOUR_CLIENT_SECRET","redirect_uris":["YOUR_REDIRECT"],"javascript_origins":["YOUR_JAVA_ORIGIN"]}}

if not yet, follow this to get your client_secret.json file

  1. Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
  2. At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
  3. Select the Credentials tab, click the Create credentials button and select OAuth client ID.
  4. Select the application type Other, enter the name "Google Calendar API Quickstart", and click the Create button.
  5. Click OK to dismiss the resulting dialog.
  6. Click the file_download (Download JSON) button to the right of the client ID.
  7. Move this file to your working directory and rename it client_secret.json.

I hope this helps. Goodluck :)

Upvotes: 1

Related Questions