All Projects → iamstuartwilson → strava

iamstuartwilson / strava

Licence: MIT license
PHP Class for the Strava API (v3)

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to strava

SmartSpin2k
Transform your spin bike into a Smart Trainer!
Stars: ✭ 88 (-24.79%)
Mutual labels:  fitness, cycling
cycling
🚴 My cycling trip from ShangHai to Wuhan in China.
Stars: ✭ 34 (-70.94%)
Mutual labels:  strava, cycling
zwift-workout-file-reference
Reference documentation for the Zwift workout file format
Stars: ✭ 54 (-53.85%)
Mutual labels:  fitness, cycling
Strava-Analysis-Tool
A Python tool to analyze and display Strava activity data.
Stars: ✭ 32 (-72.65%)
Mutual labels:  strava, cycling
ha strava
Pipe your Activity Data from Strava directly into Home Assistant
Stars: ✭ 63 (-46.15%)
Mutual labels:  strava, fitness
Strava-local-heatmap
Python script to generate a high resolution heatmap from Strava GPX files
Stars: ✭ 102 (-12.82%)
Mutual labels:  strava, cycling
bionode-ncbi
Node.js module for working with the NCBI API (aka e-utils).
Stars: ✭ 66 (-43.59%)
Mutual labels:  api-client
YuiAPI
一个浏览器API测试客户端,API文档生成器,支持chrome/firefox/新版edge
Stars: ✭ 25 (-78.63%)
Mutual labels:  api-client
strava-box
🏃‍♂️🏃‍♀️ Update a gist to contain your YTD exercise metrics from Strava
Stars: ✭ 34 (-70.94%)
Mutual labels:  strava
cv4pve-api-php
Proxmox VE Client API for PHP
Stars: ✭ 45 (-61.54%)
Mutual labels:  api-client
garmin health
Python 3.x library to access Garmin Connect Health API
Stars: ✭ 32 (-72.65%)
Mutual labels:  fitness
WikidataR
An R package for the Wikidata API
Stars: ✭ 49 (-58.12%)
Mutual labels:  api-client
drowsy
😪 Lazy integrations tool for RESTful interfaces to aid POC development and streamline integrations
Stars: ✭ 19 (-83.76%)
Mutual labels:  api-client
crates io api
API client for crates.io, the Rust crate registry.
Stars: ✭ 51 (-56.41%)
Mutual labels:  api-client
golio
League of Legends API client written in Golang
Stars: ✭ 45 (-61.54%)
Mutual labels:  api-client
go-json-spec-handler
Simple JSON API Spec Compatibility in Golang
Stars: ✭ 41 (-64.96%)
Mutual labels:  api-client
yelp-ios
No description or website provided.
Stars: ✭ 61 (-47.86%)
Mutual labels:  api-client
pygoodwe
Python library for querying Goodwe API
Stars: ✭ 20 (-82.91%)
Mutual labels:  api-client
binance-client-websocket
🛠️ C# client for Binance websocket API
Stars: ✭ 41 (-64.96%)
Mutual labels:  api-client
sia-cog
Various cognitive api for machine learning, vision, language intent alalysis. Covers traditional as well as deep learning model design and training.
Stars: ✭ 34 (-70.94%)
Mutual labels:  api-client

Build Status Minimum PHP Version Packagist Packagist Downloads

StravaApi

The class simply houses methods to help send data to and receive data from the API. Please read the API documentation to see what endpoints are available.

There is no file upload support at this time.

Installation

With Composer

composer require iamstuartwilson/strava

Or add it manually to your composer.json:

{
    "require" : {
        "iamstuartwilson/strava" : "^1.4"
    }
}

Manually

Copy StravaApi.php to your project and require it in your application as described in the next section.

Getting Started

Instantiate the class with your client_id and client_secret from your registered app:

require_once 'StravaApi.php';

$api = new Iamstuartwilson\StravaApi(
    $clientId,
    $clientSecret
);

If you're just testing endpoints/methods you can skip the authentication flow and just use the access token from your settings page.

You will then need to authenticate your strava account by requesting an access code. You can generate a URL for authentication using the following method:

$api->authenticationUrl($redirect, $approvalPrompt = 'auto', $scope = null, $state = null);

When a code is returned you must then exchange it for an access token and a refresh token for the authenticated user:

$result = $api->tokenExchange($code);

The token exchange result contains among other data the tokens. You can access them as attributes of the result object:

$accessToken = $result->access_token;
$refreshToken = $result->refresh_token;
$expiresAt = $result->expires_at;

Before making any requests you must set the access and refresh tokens as returned from your token exchange result or via your own private token from Strava:

$api->setAccessToken($accessToken, $refreshToken, $expiresAt);

Example oAuth2 Authentication Flow

examples/oauth-flow.php demonstrates how the oAuth2 authentication flow works.

  1. Choose how to load the StravaApi.php – either via Composer autoloader or by manually requiring it.
  2. Replace the three config values CALLBACK_URL, STRAVA_API_ID, and STRAVA_API_SECRET at the top of the file
  3. Place the file on your server so that it's accessible at CALLBACK_URL
  4. Point your browser to CALLBACK_URL and start the authentication flow.

The scripts prints a lot of verbose information so you get an idea on how the Strava oAuth flow works.

Example Requests

Once successfully authenticated you're able to communicate with Strava's API.

All actions that change Strava contents (post, put, delete) will need the scope set to write in the authentication flow.

Get Athlete Stats

$api->get('athletes/:id/stats');

List Athlete Activities

Some API endpoints support GET parameters:

$api->get(
    'athlete/activities',
    [
        'page' => 2,
        'per_page' => 10,
    ]
);

Post a new activity

$api->post(
    'activities', 
    [
        'name' => 'API Test',
        'type' => 'Ride',
        'start_date_local' => date('Y-m-d\TH:i:s\Z'),
        'elapsed_time' => 3600,
    ]
);

Update a athlete's weight

$api->put('athlete', ['weight' => 70]);

Releases

See CHANGELOG.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].