簡體   English   中英

NodeJS和googleapis,POST請求不起作用?

[英]NodeJS & googleapis, POST request not working?

我在帶有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);
  });
}

這個應用程式已將我授權給該范圍(如果沒有,則會引發錯誤,所以我確定這部分是正確的)。 當我列出我的gmail文件夾時,它可以正常工作。 錯誤的可能僅僅是代碼或googleapis的這一部分。 對我來說奇怪的是:

當我向Google API發出console.log請求時:

 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' },

查詢,路徑和href看起來像普通的GET,我不知道為什么。 我嘗試覆蓋它,但仍然出現“后端錯誤”。

編輯:Gmail通過GET列出文件夾,這就是我指出POST的原因。

googleapis可能是node.js的問題。 它通過GET發送數據,不需要POST和JSON。 我們必須手動進行。

從Google API調用返回的后端錯誤的錯誤代碼為503,表示“服務不可用”。

在此處檢查各種API及其狀態,並確保您嘗試訪問的服務正常運行。

https://www.google.com/appsstatus#hl=zh-CN&v=status

希望這可以幫助!

我從事類似的代碼。 該參考資料對我有所幫助。

看看: NodeJS和Goodgle Express API

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM