How to retrieve PayPal REST Api access-token using node

后端 未结 5 657
一向
一向 2021-02-10 09:03

How to get the PayPal access-token needed to leverage the REST Api by using node?

5条回答
  •  走了就别回头了
    2021-02-10 09:11

    Also, you can use axios, and async/await:

    const axios = require('axios');
    
    (async () => {
      try {
        const { data: { access_token } } = await axios({
          url: 'https://api.sandbox.paypal.com/v1/oauth2/token',
          method: 'post',
          headers: {
            Accept: 'application/json',
            'Accept-Language': 'en_US',
            'content-type': 'application/x-www-form-urlencoded',
          },
          auth: {
            username: client_id,
            password: client_secret,
          },
          params: {
            grant_type: 'client_credentials',
          },
        });
    
        console.log('access_token: ', access_token);
      } catch (e) {
        console.error(e);
      }
    })();
    

提交回复
热议问题