亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法從 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 關注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號