当我试图通过youtube的Id获取一个视频时,我遇到了一个神秘的错误:
TypeError: Cannot read property '0' of undefined
我以前使用过(16.1.0)的google-api-nodejs-client,但是在更新了包之后,它似乎不再工作了。
下面是我使用的代码:
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..
});出于某种原因,我每次都会出错。
任何帮助都将不胜感激。
发布于 2018-03-15 23:35:22
最近,有报道称,最近谷歌对node.js的搜索出现了一些错误。我已经为Gmail、Drive和Sheets确认了它们。在Youtube API上,我也发现了同样的情况。我证实,对于Youtube API,您的脚本不适用于v27.0.0、v26.0.0和v25.0.0。
当我使用24.0.0版时,效果很好。
那么,你能把评级降到24.0.0,然后再试一次吗?在那个时候,请修改从const { google } = require('googleapis');到const google = require('googleapis');我相信这些错误会被以后的更新删除。
参考资料:
如果这些信息对你没有用,我很抱歉。
https://stackoverflow.com/questions/49310299
复制相似问题