Youtube Data API V3 - Error fetching video with google.youtube.videos.list()

佐手、 提交于 2019-11-27 08:34:34

问题


I am getting a cryptic error when trying to fetch a youtube video by it's Id:

TypeError: Cannot read property '0' of undefined

I previously had this working using (16.1.0) of google-api-nodejs-client, but after updating the package it no longer seems to work.

Here is the code I am using:

const { google } = require('googleapis');
const youtube = google.youtube({ version: 'v3', auth: process.env.YOUTUBE_KEY });

youtube.videos.list({
  id: 'Txlk7PiHaGk',
  part: 'snippet, contentDetails'
}, (err, video) => {
  if (err) {
    console.error(`Error fetching Youtube Video: ${err}`);
  }
  // success..
});

For some reason my request errors every time.

Any help would be greatly appreciated


回答1:


Recently, it has been reported that the recent googleapis for node.js has some errors. I had confirmed them for Gmail API, Drive API and Sheets API. Also at Youtube API, I found the same situation. I confirmed that for Youtube API, your script didn't work for v27.0.0, v26.0.0 and v25.0.0.

When I used v24.0.0, it worked fine.

So, can you downgrade to v24.0.0 and try it again? At that time, please modify from const { google } = require('googleapis'); to const google = require('googleapis'); I believe that these errors will be removed by the future update.

References :

  • How do I update my google sheet in v4?
  • Create a gmail filter with Gmail API nodejs, Error: Filter doesn't have any criteria
  • Insufficient Permission when trying to create a folder on Google Drive via API(v3)

If this information is not useful for you, I'm sorry.



来源:https://stackoverflow.com/questions/49310299/youtube-data-api-v3-error-fetching-video-with-google-youtube-videos-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!