How can I use (insert) a (just) fetched access token in Javascript to get access to an endpoint (access ID is to be added to the endpoint URI – oauth2 – Strava API).
I tried to add the fetched access token as const and var to the URI of the endpoint, but I do not get any data returned. All is working if I manually insert the actual access_code in the URI (FETCHED_ACCESS_TOKEN), but how do I pick it up to be used automatically in the endpoint URI?
JAVASCRIPT CODE I USED:
let _data = {
client_id:"11111",
client_secret:"AAAAAAAAAAAAAAAAAAAAAAAAAAAA",
code:"exchange_code",
grant_type:"authorization_code"
}
fetch("https://www.strava.com/api/v3/oauth/token", {
method: "POST",
body: JSON.stringify(_data),
headers: {"Content-type": "application/json; charset=UTF-8"}
})
.then(response => response.json())
.then(json => console.log(json))
.then(json => {data = json})
.then(res => getActivities(res))
.catch(err => console.log(err));
const auth_link = "https://www.strava.com/oauth/token"
async function getActivities(res) {
const activities_link = "https://www.strava.com/api/v3/segments/11111111?access_token=FETCHED_ACCESS_TOKEN"
await fetch(activities_link)
.then(res => res.json())
.then(json => console.log(json));
}