MMMHUHU
2023-07-14 10:24:00
我正在我的網(wǎng)站上實(shí)施 Strava。我是 JavaScript 新手,我不明白我這樣做是否正確。我的問(wèn)題是我無(wú)法從 JSON 響應(yīng)獲取訪問(wèn)令牌。我不知道為什么。請(qǐng)幫我。我得到的反應(yīng)代碼<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>我得到的訪問(wèn)令牌為undefined
1 回答

千萬(wàn)里不及你
TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊
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));
}
添加回答
舉報(bào)
0/150
提交
取消