繁体   English   中英

Axios 响应来自 fatsecret.com 的本机令牌请求

[英]Axios React Native Token request from fatsecret.com

我需要从 fatsecret.com API 中获取 Oauth2.0 令牌,并想保存它。

我有一点 function 来请求令牌,但不断收到错误 400...

如果你能告诉我如何解决这个问题,甚至可以使用 fetch(),我将非常感激..

我卡在这个问题上很久了...

提前致谢。

邮递员令牌调用

const clientId = 'xxxxxxxxxx';
const clientSecret = 'xxxxxxxx';

async authorize () {
   const data = {
      auth: {
         user : clientId,
         password : clientSecret
      }
    }
    const config = {
      headers: { 
        'content-type': 'application/json'
      },
      'grant_type': 'client_credentials',
      'scope' : 'premier',
      json: true
    }
    const res = await axios.post('https://oauth.fatsecret.com/connect/token', {data}, [{config}]);
    console.log(res.data);
  }

尝试像这样使用 fetch:

    const clientId = 'xxxxxxxxxx';
    const clientSecret = 'xxxxxxxx';
    authorize () {
        let formData = new FormData();
        formData.append('grant_type', 'client_credentials');
        formData.append('user', clientID);
        formData.append('password', clientSecret);
        formData.append('scope', 'basic');

        fetch('https://oauth.fatsecret.com/connect/token', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: formData
        })
        .then((response) => response.json())
        .then((responseData) => {
            console.log(responseData);
        });
}

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM