未知 grant_type 状态码 401 TrustPilot 邮件邀请认证
Unknow grant_type status code 401 TrustPilot email invitation authentification
我正在尝试使用 TrustPilot API 发送电子邮件邀请进行评论。无论我做什么,结果都是未知的grant_type。文档说 grant_type 应该设置为“密码”以获取令牌,这样我就可以使用正确的选项发送邀请。
export const inviteBuyer = async (email, orderNumber) => {
const base64 = new Base64();
const secrets = base64.encode('APIKEY:APISECRET');
const authOptions = {
data: 'grant_type=password&username=myemail&password=mypassword',
headers: {
Authorization: 'Basic ' + secrets,
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const authUrl = 'https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken';
try {
const getIdentity = await HTTP.call('POST', authUrl, authOptions);
} catch (err) {
console.log(err);
}
const options = {
headers: {
token: getIdentity.access_token,
},
parameters: {
consumerEmail: email,
consumerName: 'John Doe',
referenceNumber: orderNumber,
locale: 'en',
senderEmail: 'OurEMail', // potentiellmeent
serviceReviewInvitation: {
// preferredSendTime: '2013-09-07T13:37:00',
// redirectUri: 'http://trustpilot.com',
tags: ['buyer'],
// templateId: '507f191e810c19729de860ea',
},
},
};
try {
const resp = await HTTP.call(
'POST',
'https://invitations-api.trustpilot.com/v1/private/business-units/OurBusinessUnitId/email-invitations',
options
);
console.dir(resp);
} catch (err) {}
console.log(err);
};
最初的问题使用 payload
键来指定正文,后来 data
。
但是,要使用 Meteor HTTP 客户端发送原始 HTTP 请求正文,必须使用 content
:
const authOptions = {
content: 'grant_type=password&username=myemail&password=mypassword',
headers: {
Authorization: 'Basic ' + secrets,
'Content-Type': 'application/x-www-form-urlencoded',
},
};
我正在尝试使用 TrustPilot API 发送电子邮件邀请进行评论。无论我做什么,结果都是未知的grant_type。文档说 grant_type 应该设置为“密码”以获取令牌,这样我就可以使用正确的选项发送邀请。
export const inviteBuyer = async (email, orderNumber) => {
const base64 = new Base64();
const secrets = base64.encode('APIKEY:APISECRET');
const authOptions = {
data: 'grant_type=password&username=myemail&password=mypassword',
headers: {
Authorization: 'Basic ' + secrets,
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const authUrl = 'https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken';
try {
const getIdentity = await HTTP.call('POST', authUrl, authOptions);
} catch (err) {
console.log(err);
}
const options = {
headers: {
token: getIdentity.access_token,
},
parameters: {
consumerEmail: email,
consumerName: 'John Doe',
referenceNumber: orderNumber,
locale: 'en',
senderEmail: 'OurEMail', // potentiellmeent
serviceReviewInvitation: {
// preferredSendTime: '2013-09-07T13:37:00',
// redirectUri: 'http://trustpilot.com',
tags: ['buyer'],
// templateId: '507f191e810c19729de860ea',
},
},
};
try {
const resp = await HTTP.call(
'POST',
'https://invitations-api.trustpilot.com/v1/private/business-units/OurBusinessUnitId/email-invitations',
options
);
console.dir(resp);
} catch (err) {}
console.log(err);
};
最初的问题使用 payload
键来指定正文,后来 data
。
但是,要使用 Meteor HTTP 客户端发送原始 HTTP 请求正文,必须使用 content
:
const authOptions = {
content: 'grant_type=password&username=myemail&password=mypassword',
headers: {
Authorization: 'Basic ' + secrets,
'Content-Type': 'application/x-www-form-urlencoded',
},
};