我试图通过它的Id获取YouTube视频时遇到了一个神秘的错误:
TypeError: Cannot read property '0' of undefined
我以前使用google-api-nodejs-client
的(16.1.0)工作,但更新包后它似乎不再起作用。
这是我正在使用的代码:
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..
});
出于某种原因,我的请求每次都会出错。
任何帮助将不胜感激
最近,据报道,最近的googleapis for node.js有一些错误。我已针对Gmail API,Drive API和Sheets API确认了这些内容。同样在Youtube API,我发现了同样的情况。我确认对于Youtube API,您的脚本不适用于v27.0.0,v26.0.0和v25.0.0。
当我使用v24.0.0时,它工作正常。
那么,你可以降级到v24.0.0然后再试一次吗?那时候,请从const { google } = require('googleapis');
修改为const google = require('googleapis');
我相信这些错误将在未来的更新中删除。
如果这些信息对您没用,我很抱歉。