这是使用 COINBASE API 成功授权后请求访问令牌的代码
router.get('/auth/coinbase/token', function (req, res) {
var body = {
"grant_type": "authorization_code",
"code": req.query.code,
"client_id": process.env.COINBASE_CLIENT_ID,
"client_secret": process.env.COINBASE_CLIENT_SECRET,
"redirect_uri": process.env.COINBASE_CALLBACK_URL
};
console.log(body);
request.post({
url: 'https://api.coinbase.com/oauth/token',
headers: {
'Content-Type': 'application/json'
},
json: {
"grant_type": "authorization_code",
"code": req.query.code,
"client_id": process.env.COINBASE_CLIENT_ID,
"client_secret": process.env.COINBASE_CLIENT_SECRET,
"redirect_uri": process.env.COINBASE_CALLBACK_URL
}
}, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred and handle it
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
res.send(body)
});
});
但是在发送发布请求时,我收到此错误
{error:“invalid_grant”,error_description:“提供的授权授权无效,过期……化请求,或已发布给另一个客户端。”}
帮我解决这个问题。谢谢