为了账号安全,请及时绑定邮箱和手机立即绑定

无法从 json 响应获取访问令牌

无法从 json 响应获取访问令牌

MMMHUHU 2023-07-14 10:24:00
我正在我的网站上实施 Strava。我是 JavaScript 新手,我不明白我这样做是否正确。我的问题是我无法从 JSON 响应获取访问令牌。我不知道为什么。请帮我。我得到的反应代码<script>    const auth_link = "https://www.strava.com/oauth/token"function getActivites(res){console.log('response2',res.json());    const activities_link = `https://www.strava.com/api/v3/athlete/activities?access_token=${res.access_token}`    fetch(activities_link)        .then((res) => console.log(res.json()))}function reAuthorize(){    fetch(auth_link,{        method: 'post',        headers: {            'Accept': 'application/json, text/plain, */*',            'Content-Type': 'application/json'        },        body: JSON.stringify({            client_id: 'xxxx',            client_secret: 'xxxxx',            refresh_token: 'xxxxx',            grant_type: 'refresh_token'        })    })    .then(res => {        var response = res.json();        var access_token = response.access_token;        console.log('response',access_token)       // getActivites(res)        })}reAuthorize()</script>我得到的访问令牌为undefined
查看完整描述

1 回答

?
千万里不及你

TA贡献1784条经验 获得超9个赞

function reAuthorize() {

  fetch(auth_link, {

    method: "post",

    headers: {

      Accept: "application/json, text/plain, */*",

      "Content-Type": "application/json"

    },

    body: JSON.stringify({

      client_id: "55077",

      client_secret: "801a8541e8ae55cffee584a48c5bb6a233dea9a0",

      refresh_token: "08342cdf3250da9e0d1b53303fa40faf0d05965d",

      grant_type: "refresh_token"

    })

  }).then(response => response.json())

    .then(data => console.log(data));

}


查看完整回答
反对 回复 2023-07-14
  • 1 回答
  • 0 关注
  • 68 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信