paypal授权unsupported_grant_type axios发布请求中的授予类型为NULL

时间:2020-04-05 00:08:14

标签: api react-native paypal axios

我正在尝试将Paypal集成到我的应用中,但出现400错误[unsupported_grant_type]授予类型为NULL

axios
      .post(
        'https://api.sandbox.paypal.com/v1/oauth2/token',
        { grant_type: 'client_credentials' },
        {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          auth: {
            username:
              'clientId',
            password:
              'secret'
          }
        }
      )
      .then(response => {
        console.log('response', response.data);

      })
      .catch(err => {
        // console.log('error', { ...err });
        console.log('error', err);
      });

我做错了什么?

注意:它在邮递员中工作正常

1 个答案:

答案 0 :(得分:2)

我找到了解决方法。

束紧身体。

添加

const qs = require('querystring');
qs.stringify({ grant_type: 'client_credentials' })