我正在尝试从我从 eBay 获得的刷新 token 中获取 access_token。我正在使用 Axios,但我不断收到 不支持在请求中获取授权类型 错误。
const refreshToken = 'xxxxxxxx';
const appID = 'xxxxxxx';
const certID = 'xxxxxx';
const scopes = [
'https://api.ebay.com/oauth/api_scope',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
'https://api.ebay.com/oauth/api_scope/sell.account',
'https://api.ebay.com/oauth/api_scope/sell.inventory'
]
const params = {
grant_type: 'refresh_token',
refresh_token: refreshToken,
'scope': encodeURI(scopes.join(" ")),
// scope: scopes,
const token = Buffer.from(`${appID}:${certID}`);
const URL = 'https://api.ebay.com/identity/v1/oauth2/token'
const { data } = await axios.post(URL, params, {
'headers': {
'Authorization': `Basic ${token.toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
})
最佳答案
原来你必须对整个请求主体进行 UriEncode,利用
Node 的 querystring.encode()
:
const qs = require("querystring")
...
const { data } = await axios.post(URL, qs.encode(params), {
'headers': {
'Authorization': `Basic ${token.toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
})
关于node.js - 如何使用 Ebay 的刷新 token 获取访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66744901/