错误一:

代码如下——

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
app.get('/connect', function(req, res){
payload = {"client_id" : config.Client_ID,
"client_secret" : config.Client_Secret,
"refresh_token" : 'https://localhost/connect',
"speech": "lalallalalalala"
}
url = "https://api.amazon.com/auth/o2/token/?grant_type=refresh_token&client_id=" + config.Client_ID +
"&client_secret=" + config.Client_Secret;
request.post({
url:url,
headers: {
},
formData: payload
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
res.end(body);
});
});

报错"error_description":"The request is missing a required parameter : Content-Type","error":"invalid_request"

**解决方案:**在headers 里添加——

1
2
3
4
headers: {
" Accept": "application/x-www-form-urlencoded",
"Content-Type":"application/x-www-form-urlencoded",
},

错误二:

报错如下——
"error_description":"Malformed request","error":"invalid_request"

解决方案,使用requestrequest.post 函数体内请求url错误,更改如下即可:

1
2
3
url = "https://api.amazon.com/auth/o2/token/?grant_type=refresh_token&client_id=" + config.Client_ID +
"&client_secret=" + config.Client_Secret;