【问题标题】:How to get access_token using refresh token from Ebay?如何使用来自 Ebay 的刷新令牌获取 access_token?
【发布时间】:2021-03-22 11:12:14
【问题描述】:

我正在尝试从我从 eBay 获得的刷新令牌中获取 access_token。我正在使用 Axios,但我不断收到 getting grant type in request is not supported 错误。

  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',
      },
    })

【问题讨论】:

    标签: node.js openid-connect ebay-api ebay-sdk


    【解决方案1】:

    事实证明,您必须对整个请求正文进行 UriEncode,使用 节点的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',
      },
    })
    

    【讨论】:

      猜你喜欢
      • 2015-07-15
      • 2017-11-20
      • 2020-06-03
      • 1970-01-01
      • 2020-02-26
      • 2020-09-25
      • 2019-10-26
      • 2015-07-19
      相关资源
      最近更新 更多