I’ve tried quite a few things and read a lot of examples of using the data returned by Fetch as an object to put into a table or similar but I can’t seem to get it. The following code authorises the Strava user to use my test App and then gets the Users last 30 activities. Once data is returned as a Promise I can view it in the console, but not use it. I’m a bit of a novice so just need some direction on how to use this data in table.
//my code is below
<script>
//reAuthorize Click
function Authorize() {
document.location.href = "https://www.strava.com/oauth/authorize?client_id=73630&redirect_uri=https://localhost:44370/strava/index&response_type=code&scope=activity:read_all"
}
const codeExchangeLink = `https://www.strava.com/api/v3/oauth/token`
function codeExchange() {
fetch(codeExchangeLink, {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({
client_id: '@ViewBag.cId',
client_secret: '@ViewBag.cSec',
code: '@ViewBag.code',
//need to do this to get a new refresh token that 'reads all' and issues a new Access Token - refer to comments below
grant_type: 'authorization_code'
})
})
.then(res => res.json())
.then(res => getActivities(res))
}
// getActivities
const auth_link = "https://www.strava.com/oauth/token"
function getActivities(res) {
var obj;
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()))
}
</script>
<form asp-action="Index" method="get">
<input type="text" id="cId" value="@ViewBag.cId" />
<input type="text" id="cSec" value="@ViewBag.cSec" />
<input type="text" id="rT" value="@ViewBag.rT" />
<input type="text" id="code" value="@ViewBag.code" />
<input type="text" id="test" />
</form>
<input type="button" onclick="Authorize()" value="ReAuthorise" />
<input type="button" onclick="codeExchange()" value="Get Activities" />