【问题标题】:YouTube API TypeError: callback is not a functionYouTube API TypeError:回调不是函数
【发布时间】:2018-09-16 16:52:42
【问题描述】:

我试图用 nodejs https://developers.google.com/youtube/v3/docs/search/list#usage 收集这样的搜索结果

还有功能

function searchListByKeyword(auth, requestData) {
  var service = google.youtube('v3');
  var parameters = removeEmptyParameters(requestData['params']);
  parameters['auth'] = auth;
  service.search.list(parameters, function(err, response) {
    if (err) {
      console.log('The API returned an error: ' + err);
      return;
    }
    console.log(response);
  });
}

函数必须返回搜索结果的集合,但在我的例子中它返回请求

$ node quickstart
Request {
  _events:
   { error: [Function: bound ],
     complete: [Function: bound ],
     pipe: [Function] },
  _eventsCount: 3,
  _maxListeners: undefined,
  url: 'https://www.googleapis.com/youtube/v3/search',
  method: 'GET',
  paramsSerializer: [Function],
  headers:
   { 'Accept-Encoding': 'gzip',
     'User-Agent': 'google-api-nodejs-client/28.1.0 (gzip) google-api-nodejs-client/0.12.0',
     Authorization: 'Bearer ya29.GluVBXvsx3nP15QlV-MqcypX1eEvDQ3BuXttbfQyR7ZlTpfO26sZnrh7Sl0sWsOCdGsJWHpHtE9XJv0jDqoWmVOZoJbQLqqQs3ujIPlATDQBHxu5nNorO8JBCE6y',
     host: 'www.googleapis.com' },
  params: { maxResults: '25', part: 'snippet', q: 'surfing', type: 'qwe' },
  maxContentLength: 2147483648,
  validateStatus: [Function],
  uri:
   Url {
     protocol: 'https:',
     slashes: true,

毕竟这会引发错误

C:\Users\wwwba\Desktop\youtube\node_modules\google-auth-library\lib\auth\oauth2client.js:341
        callback(err, result, response);
        ^

TypeError: callback is not a function
    at OAuth2Client.postRequest (C:\Users\wwwba\Desktop\youtube\node_modules\google-auth-library\lib\auth\oauth2client.js:341:9)
    at postRequestCb (C:\Users\wwwba\Desktop\youtube\node_modules\google-auth-library\lib\auth\oauth2client.js:297:23)
    at Request._callback (C:\Users\wwwba\Desktop\youtube\node_modules\google-auth-library\lib\transporters.js:113:17)
    at Request.self.callback (C:\Users\wwwba\Desktop\youtube\node_modules\request\request.js:186:22)
    at Request.emit (events.js:180:13)
    at Request.<anonymous> (C:\Users\wwwba\Desktop\youtube\node_modules\request\request.js:1163:10)
    at Request.emit (events.js:180:13)
    at IncomingMessage.<anonymous> (C:\Users\wwwba\Desktop\youtube\node_modules\request\request.js:1085:12)
    at Object.onceWrapper (events.js:272:13)
    at IncomingMessage.emit (events.js:185:15)

谁能告诉我我做错了什么。谢谢

【问题讨论】:

    标签: node.js youtube-data-api


    【解决方案1】:

    解决方案比我想象的要简单。 我卸载 googleapis 和 google-auth-library 并安装它们的旧版本

     "google-auth-library": "^0.12.0",
     "googleapis": "^21.3.0"
    

    google,为新版本重写您的 api 或警告我们必须安装旧版本

    【讨论】:

    • 感谢您为我工作!我猜谷歌的人没有时间为像我们这样的普通人更新文档:(
    • 感谢您发布您找到的解决方案。 :) 考虑接受它,以便其他人可以看到问题已解决。
    猜你喜欢
    • 1970-01-01
    • 2017-01-31
    • 2018-01-22
    • 2018-06-05
    • 2014-09-07
    • 2017-03-28
    • 2016-10-25
    • 1970-01-01
    相关资源
    最近更新 更多