节点js Adwords Api

我正在使用Node JS服务器,并试图从Adwords API获取访问令牌。 为了执行POST请求,我使用npm( https://www.npmjs.org/package/curler )的curler。 这是代码示例:

var login = 'mymail@gmail.com'; var pass = 'mypassword'; var data = JSON.stringify({ Email: login, Passwd : pass, accountType: 'GOOGLE', service: 'adwords', source: 'adwordstest' }); var options = { method: "POST", url: 'https://www.google.com/accounts/ClientLogin', headers: { 'Content-Type': 'application/json' }, data: data, timeout: 5000, connectionTimeout: 5000 }; var startDate = Date.now(); curl.request(options, function(err, res, bodyData) { var duration = (Date.now() - startDate); if (err) { console.log(err); } else { console.log('statusCode: %s', res.statusCode); console.log('bodyData: %s', bodyData); } console.log("curler (libcurl) performed http request in %s ms. dnsTime: %s, connectTime: %s, preTransferTime: %s, startTransferTime: %s, totalTime: %s", duration, res.dnsTime, res.connectTime, res.preTransferTime, res.startTransferTime, res.totalTime); }); 

我得到的答复是

 statusCode: 403 bodyData: Error=BadAuthentication 

基本上说,login信息是错误的,而不是。 无法弄清楚我是否select了错误的实现,或只是缺less一个标题或其他东西。

以下是我用来获取全新访问令牌的代码: https : //github.com/ErikEvenson/googleads-node-lib/blob/v0.0.17/services/adWordsService.js#L206-L241 。 访问令牌以credentials.access_token结尾。

  self.refresh = function(done) { // check if current credentials haven't expired if (self.credentials && Date.now() < self.credentials.expires) { // behave like an async setTimeout(function() {done(null);}, 0); return; } else { // throw away cached client self.client = null; var qs = { refresh_token: self.options.ADWORDS_REFRESH_TOKEN, client_id: self.options.ADWORDS_CLIENT_ID, client_secret: self.options.ADWORDS_SECRET, grant_type: 'refresh_token' }; request.post( { qs: qs, url: self.tokenUrl }, function(error, response, body) { self.credentials = JSON.parse(body); self.credentials.issued = Date.now(); self.credentials.expires = self.credentials.issued - self.credentials.expires_in; done(error); } ); return; } };