NodeJS&googleapis,POST请求不工作?

我用hapi在NodeJS的google api上遇到了问题。 我用npm install googleapis和google-auth-library下载了文件。 一切安装正确。

function listData(auth) { let webmasters = google.webmasters('v3'); webmasters.searchanalytics.query({ auth: auth, siteUrl: 'http%3A%2F%2Falanmroczek.pl%2F', startDate: "2016-09-20", endDate: "2016-10-14" }, function(err, response) { if (err) { console.log('The API returned an error: ' + err); return; } console.log(response); }); } 

我有权通过这个应用程序的范围(如果不是它会引发错误,所以我相信这部分是okey)。 当我完成列出我的Gmail文件夹,它完美的作品。 错误可能只是这部分代码或googleapis。 对我来说奇怪的是:

当我console.log请求谷歌API:

  protocol: 'https:', slashes: true, auth: null, host: 'www.googleapis.com', port: null, hostname: 'www.googleapis.com', hash: null, search: '?startDate=2016-09-20&endDate=2016-10-14', query: 'startDate=2016-09-20&endDate=2016-10-14', pathname: '/webmasters/v3/sites/http%3A%2F%2Falanmroczek.pl%2F/searchAnalytics/query', path: '/webmasters/v3/sites/http%3A%2F%2Falanmroczek.pl%2F/searchAnalytics/query?startDate=2016-09-20&endDate=2016-10-14', href: 'https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Falanmroczek.pl%2F/searchAnalytics/query?startDate=2016-09-20&endDate=2016-10-14' }, 

查询,path和href看起来像正常的GET,我不知道为什么。 我试图覆盖它,但仍然得到“后端错误”。

编辑:通过GET的Gmail列表文件夹,这就是为什么我指出了POST。

这可能是与node.js的googleapis问题。 它通过GET发送数据不需要POST和JSON。 我们必须手动完成。

从Google API调用返回的后端错误将以503错误代码表示“服务不可用”。

在这里检查各种API和它的状态,并确保您尝试点击的服务正常运行。

https://www.google.com/appsstatus#hl=en&v=status

希望这可以帮助!

我工作在类似的代码。 这个参考帮助了我。

只需看一下: NodeJS&Goodgle Express API