2

I've just copied a simple example from Youtube docs but it fails. I want to implement Youtube data API in my project.

Following these links:

Youtube data api quickstart documentation

Youtube data api quickstart github repo

  1. I've created a new project in Google Developers Console
  2. Added OAuth credentials
  3. Downloaded my "client_secret.json" file
  4. Copied quickstart project into my working folder

But when I run this script an error occurs:

~/workspace/youtube/quickstart $ node test-1.js

/home/ubuntu/workspace/youtube/quickstart/test-1.js:31
   var clientSecret = credentials.installed.client_secret;
                                      ^

TypeError: Cannot read property 'client_secret' of undefined
   at authorize (/home/ubuntu/workspace/youtube/quickstart/test-1.js:31:43)
   at processClientSecrets (/home/ubuntu/workspace/youtube/quickstart/test-1.js:20:3)
   at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3)

Where did I possibly make a mistake and how to fix it?

1
  • Try debug the code. You can figure out what is happening. Cheers Commented Jan 22, 2018 at 4:33

2 Answers 2

1

The issue is with the client_secret json file. Try parsing the json using some online json parser. Since the parsing failed or could not find json file at the specificed location the credentials variable is undefined. Js engine throws error as it couldn't read client_secret of undefined.

Sign up to request clarification or add additional context in comments.

Comments

0

Please check you json file. If your json file start with {web:{client... you have chosen to create credentials for a Web application and this example won't work unless you change "installed" to "web"on your code.

The example is set to work perfectly if you choose to create credentials for a computer application. Then it will generate a json file with "installed".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.