0

在以下代码中,我为 API 的 OAuth2 指定了 Authorization with Bearer。但我不断得到401 - authorization required。我不知道为什么身份验证不起作用,我大摇大摆地尝试了它,爪子但一切都起作用了,但在 Node 端却没有。

let mailOpt = {
      uri: "https://api.sendgrid.com/v3/contactdb/recipients",
      method: "POST",
      header: {
        "Authorization": `Bearer ${account.SENDGRID_ACCESS_TOKEN}`
      },
      body: "[\n" +
            "  {\n" +
            `    \"email\": \"${response[0].email}\"\n` +
            "  }\n" +
            "]"
}

当我打印出实际的mailOpt时,我得到了下面的信息。一切看起来都很好。

MAILopt { uri: 'https://api.sendgrid.com/v3/contactdb/recipients',
  method: 'POST',
  header: 
   { Authorization: 'Bearer access_token' },
  body: '[\n  {\n    "email": "voqes@inboxbear.com"\n  }\n]' }
4

1 回答 1

0

在您的选择中,您拥有该属性header,但它应该是headers,这就是该"Authorization"部分被忽略的原因。

此外,不确定是否uri是有效属性,但url肯定是。

于 2018-01-24T04:56:47.677 回答