Sendgrid API:"提供的授权许可无效,已过期或已撤销"

时间:2016-11-16 17:49:50

标签: node.js api express sendgrid

我已经通过过去的Stack帖子进行了挖掘,似乎没有解决问题的方法。我使用生成的API密钥(不是API密钥ID),我已经允许所有权限,我甚至尝试打开第二个帐户并从那里尝试。这是代码:

// Create new mail object.
var mail = new helper.Mail();

// Set 'from' for email.
var from = new helper.Email("owner@site.com", "First Last");
mail.setFrom(from)

// Set 'subject' for email.
mail.setSubject("SchemeBeam Email Verification");

// Create a new personalization, which will allow us to define
// an individual to send this email too, as well as define
// substitutions to use so we can replace a string, such as
// '%hash'%, in the email template with the real hash for this
// user.
var personalization = new helper.Personalization()
var to = new helper.Email("test1@example.com", "Example User");
personalization.addTo(to);

// Set hash substituion.
//var substitution = new helper.Substitution("%hash%", md5Hash);
//personalization.addSubstitution(substitution);

// Let's send it.
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
var request = sg.emptyRequest({
  method: 'POST',
  path: '/v3/mail/send',
  body: mail.toJSON(),
});

sg.API(request, function(error, response) {
  // Handle the response here.
  console.log(response.statusCode);
  console.log(response.body);
  console.log(response.headers);
});

这是错误:

{ errors: 
   [ { message: 'The provided authorization grant is invalid, expired, or revoked',
       field: null,
       help: null } ] }
{ server: 'nginx',
  date: 'Wed, 16 Nov 2016 17:45:14 GMT',
  'content-type': 'application/json',
  'content-length': '116',
  connection: 'close',
  'x-frame-options': 'DENY' }

0 个答案:

没有答案