Skip to main content
Solved

Can someone please help fix this javascript connection?


Forum|alt.badge.img

I have written a javascript command with the help of Chat GPT3 (I am not a developer) but would love some community assistance here! I'm looking to import activity data from Strava into an Equals spreadsheet. 

Can someone help me understand what I need to do to fix this? Any support is very appreciated!

Here's what I have:

 

const equals = require("equals"); const axios = require("axios"); const STRAVA_ACCESS_TOKEN = equals.getSecret("strava_api_key"); const STRAVA_ATHLETE_ID = equals.getSecret("strava_athlete_id"); const TABLE_NAME = "Activities"; const postData = async () => { const resp = await axios({ method: "post", url: `https://www.strava.com/api/v3/athletes/${STRAVA_ATHLETE_ID}/activities`, headers: { Authorization: `Bearer ${STRAVA_ACCESS_TOKEN}` } }); return resp.data; }; const data = await postData(); equals.addHeaders(["Name", "Sport Type", "Elapsed Time", "Description", "Distance"]); for(const record of data) { equals.addRow([ record.name, record.sport_type, record.elapsed_time, record.description, record.distance ]); }

 

 

Best answer by igoramadas

The method should be "get" and not "post".

But more importantly, the access token is not the same as your API key. You actually should use the API key to fetch the access token. But explaining the whole OAuth2 flow here might be a bit of a stretch...

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img

Forum|alt.badge.img+7
  • Hub Climber
  • 19 replies
  • Answer
  • January 31, 2023

The method should be "get" and not "post".

But more importantly, the access token is not the same as your API key. You actually should use the API key to fetch the access token. But explaining the whole OAuth2 flow here might be a bit of a stretch...


Forum|alt.badge.img+1
  • Hub Starter
  • 6 replies
  • November 15, 2024

I wrote a web app to import strava activities into google calendar. It can also write all your activities to a google sheets training log. You are welcome to give it a try here:  https://gcalimporter-sphq7qewrq-wn.a.run.app

(it's hosted on google cloud hence the odd url)


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept, you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings