PayPal授权:axios post请求中的unsupported_grant_type Grant Type为空

3

我正在尝试在我的应用程序中整合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);
      });

我做错了什么?

注意:在 Postman 中它可以正常工作。

1个回答

2
我找到了解决方案...
将正文字符串化...
添加
const qs = require('querystring');
qs.stringify({ grant_type: 'client_credentials' })

6
你不需要做任何要求,只需在URL末尾添加"?grant_type=client_credentials",并发送一个没有请求体的请求。 - Mirko

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接