Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot read property 'client_secret' of undefined

I have tried to create a sample program using Node.js, following instructions from https://developers.google.com/google-apps/activity/v1/quickstart/nodejs

I throws an error saying cannot read property 'client_secret' of undefined when trying to run it.

Looking for your valuable suggestions.

Thanks in advance.

like image 224
mahesh peddi Avatar asked Jul 20 '16 17:07

mahesh peddi


5 Answers

var clientSecret = credentials.installed.client_secret; In this line credentials is pointing to client_secret.json so the first key has to be "installed". In my case the key was "web" and that was causing the error. I just renamed the key "web" to "installed".

like image 191
javier Cuervas Avatar answered Nov 06 '22 19:11

javier Cuervas


Since there is no key named "installed", it's parsing it to be undefined.

In credentials.json change the key "web" to "installed". Probably the docs need to change from Google's side.

Before

enter image description here

After

enter image description here

like image 10
mythicalcoder Avatar answered Nov 06 '22 19:11

mythicalcoder


enter image description here

It seems you have missed Step 1: Turn on the Google Apps Activity API.

After creating the Credentials:

f. Click the file_download (Download JSON) button to the right of the client ID.

g. Move this file to your working directory and rename it client_secret.json. Put it in your project folder.

like image 4
ReyAnthonyRenacia Avatar answered Nov 06 '22 19:11

ReyAnthonyRenacia


Your client_secret.json file needs to have the line below:

"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]

instead of the lines like below:

"javascript_origins":
    [
      "http://localhost:8080",
      "http://localhost:1453",
      "http://127.0.0.1:1453",
      "http://localhost"
    ]

Also you may want to change chain head in client_secret.json from web to installed, or vise versa.

like image 3
cagcak Avatar answered Nov 06 '22 20:11

cagcak


I had this problem, but I had the wrong type of credentials file. I initially used "Web Server (Nodejs)...", and it had the "web" heading instead of the "installed", but when I did it again, and selected "Windows UI (cmd line)", I got the file with the correct format.

like image 2
Sako73 Avatar answered Nov 06 '22 21:11

Sako73