【问题标题】:googleapis throwing 'undefined' error in apirequest.jsgoogleapis 在 apirequest.js 中抛出“未定义”错误
【发布时间】:2019-04-04 22:26:31
【问题描述】:

NodeJs googleapis 模块有问题。

我的简单测试:

var google = require('googleapis');
var analytics = new google.analytics('v3');
var OAuth2 = google.auth.OAuth2;
var config = require('./config.js')

var oauth2Client = new OAuth2(config.clientId, config.clientSecret);

// Retrieve tokens via token exchange explained above or set them:
oauth2Client.setCredentials({
  access_token: config.accessToken,
  refresh_token: config.refreshToken
});

// get management list
analytics.management.accounts.list({ auth: oauth2Client }, function(err, response) {
  console.log(err)
  console.log(response)
});

我的结果:

Type Error: Cannot read property 'params' of undefined
    at createAPIRequest (/Users/gkburdett/Documents/Applications/maestro-and-scout/node_modules/googleapis/lib/apirequest.js:76:39)
    at Object.Analytics.management.accounts.list (/Users/gkburdett/Documents/Applications/maestro-and-scout/node_modules/googleapis/apis/analytics/v3.js:342:16)
    at Object.<anonymous> (/Users/gkburdett/Documents/Applications/maestro-and-scout/server/google/test/simpleTest.js:13:31)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

parameters.context.google 是一个空白对象。

如果我将 apirequest.js 第 76 行更改为空白对象,它会起作用。我在 GitHub 上提交了一个问题,但如果这是库的问题,我很难相信我是唯一一个遇到此问题的人。

【问题讨论】:

    标签: node.js google-api google-api-nodejs-client


    【解决方案1】:

    将第 2 行更改为:

    var analytics = new google.analytics('v3');
    

    到:

    var analytics = google.analytics('v3');
    

    调用analytics.management.accounts.list 时,传递给createAPIRequest 的上下文选项超出了初始google 对象的范围。

    【讨论】:

      【解决方案2】:

      我的 api 中有一个名称以“google”开头的方法,它覆盖了库的一些内部配置对象。我不是评判任何人的专家,但在一个对象中混合内部和用户定义的方法似乎是一种糟糕的设计

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-30
        • 2014-07-09
        • 2018-11-15
        • 2019-04-19
        • 2016-12-14
        • 2016-02-11
        • 2014-09-21
        相关资源
        最近更新 更多