After lots of experimentation and several errors later, I managed to successfully integrate Strava’s API into my website. The official documentation can be found here – https://strava.github.io/api/, for further support I used this PHP specific Github repository (https://github.com/iamstuartwilson/strava).
When users register to my site they are directed to this page stating when their chosen plan starts as well as the link to connect to Strava…
Logging in to Strava will then direct users to this authorisation page. If the user accepts the authorisation, their Strava access token is stored in my database and I am able to access their activity data…
I access users Strava data at the end of each week, comparing their weekly total to the required total of selected plan. If users run enough then they receive a tip and can progress to the next week. However, if not, they are prompted to run more! From feedback, my target audience preferred that it checks at the end of the week rather than each day, as this allows users more flexibility with the training.
Snippet of my integration of Strava’s API:
I set up localhost on mac so I can locally test my php files:
I set up a user database for my registration/login
When users register to my site, their details are added to the user database. I have set the training difficulty field type to enum, so Beginner = 1, Intermediate = 2 and Advanced = 3. I have also added a sign up date field of type=timestamp. So when users log in, it pulls in their sign up date to determine what week they are currently on. All the training plans start on a Monday so if the users sign up date is not a Monday then the guide commences from the following Monday. The database also stores users access token from Strava’s API; when the user connects with Strava through the OAuth protocol, their token gets added to the database. This then allows me to pull in their personal Strava data in order to see if they have done enough miles to progress to the next week.
FEEDBACK: Originally, I was using MySQL statements to connect, select and update the databases. However, from feedback it was suggesting to look into Propel, an orm library. I installed propel using terminal and have used Propels Basic C.R.U.D operations.