You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js使用youtube-video-api认证超时:无法获取令牌求助

Fixing YouTube Authentication Timeout Error with youtube-video-api

Hey there, I’ve run into similar timeout headaches with OAuth-based packages before, so let’s break down how to fix this "Cannot retrieve the token. Timeout exceeded" error you’re hitting.

First, let’s recap the error you’re seeing for clarity:

Can not authenticate Error: Cannot retrieve the token. Timeout exceeded at Timeout._onTimeout (/opt/lampp/htdocs/mastermind/node_modules/nightmare-google-oauth2/index.js:179:18) at ontimeout (timers.js:469:11) at tryOnTimeout (timers.js:304:5) at Timer.listOnTimeout (timers.js:264:5)

This error traces back to the nightmare-google-oauth2 dependency that youtube-video-api uses under the hood. Here are the most actionable fixes to try:

  • Check your network and firewall settings
    Timeout errors almost always start with network access issues. Make sure your server/development environment can reach Google’s OAuth endpoints (like accounts.google.com). If you’re behind a proxy or firewall, whitelist these domains first. Test connectivity quickly with a simple curl https://accounts.google.com to confirm.

  • Bump up the OAuth request timeout
    The default timeout for nightmare-google-oauth2 might be too short for your network speed. You can adjust this when initializing the YouTube API client by adding a timeout parameter (in milliseconds):

    const YouTube = require('youtube-video-api');
    const youtubeClient = new YouTube({
      clientId: 'YOUR_CLIENT_ID',
      clientSecret: 'YOUR_CLIENT_SECRET',
      redirectUrl: 'YOUR_REDIRECT_URI',
      timeout: 60000 // 60 seconds, tweak this as needed
    });
    
  • Double-check your OAuth credentials
    Even though the error says timeout, invalid credentials can sometimes cause requests to hang instead of failing immediately. Verify:

    • Your client ID and secret exactly match what’s in your Google Cloud Console project
    • The redirect URI in your code is identical to the one registered in Google Cloud (including HTTP/HTTPS and trailing slashes if present)
    • The YouTube Data API v3 is enabled for your project in Google Cloud Console
  • Update or roll back dependent packages
    Outdated versions of youtube-video-api or nightmare-google-oauth2 might have bugs causing timeouts. Try updating both first:

    npm update youtube-video-api nightmare-google-oauth2
    

    If updating doesn’t help, check the package’s GitHub issues for version-specific reports and try downgrading to a known stable release.

  • Test locally first
    If you’re running this on a remote server, try the same code on your local machine. This will help you rule out server-specific network restrictions or environment quirks that could be causing the timeout.

内容的提问来源于stack exchange,提问作者Suresh Prajapati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:30:42