2017 © Pedro Peláez
 

library strava

PHP implementation of the Strava V3 API

image

iamstuartwilson/strava

PHP implementation of the Strava V3 API

  • Monday, July 2, 2018
  • by iamstuartwilson
  • Repository
  • 16 Watchers
  • 86 Stars
  • 6,231 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 28 Forks
  • 2 Open issues
  • 15 Versions
  • 15 % Grown

The README.md

Build Status Minimum PHP Version Packagist Packagist Downloads, (*1)

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., (*2)

There is no file upload support at this time., (*3)

Installation

With Composer

``` shell composer require iamstuartwilson/strava, (*4)


Or add it manually to your `composer.json`: ``` 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., (*5)

Getting Started

Instantiate the class with your client_id and client_secret from your registered app:, (*6)

``` php require_once 'StravaApi.php';, (*7)

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


If you're just testing endpoints/methods you can skip the authentication flow and just use the access token from your [settings page](https://www.strava.com/settings/api). You will then need to [authenticate](https://developers.strava.com/docs/authentication/) your strava account by requesting an access code. You can generate a URL for authentication using the following method: ``` php $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:, (*9)

``` php $result = $api->tokenExchange($code);, (*10)


The token exchange result contains among other data the tokens. You can access them as attributes of the result object: ```php $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:, (*11)

``` php $api->setAccessToken($accessToken, $refreshToken, $expiresAt);, (*12)


## 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 ``` php $api->get('athletes/:id/stats');

List Athlete Activities

Some API endpoints support GET parameters:, (*13)

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


### Post a new activity ``` php $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

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

Releases

See CHANGELOG.md., (*16)

The Versions

02/07 2018

dev-master

9999999-dev

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

02/03 2017

1.3.0

1.3.0.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

10/02 2017

dev-feature/25/webhook

dev-feature/25/webhook

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

26/10 2016

1.2.2

1.2.2.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

26/10 2016

dev-feature/add-license

dev-feature/add-license

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

04/10 2016

1.2.1

1.2.1.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

12/07 2016

1.2.0

1.2.0.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

28/05 2016

1.1.2

1.1.2.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

26/01 2016

1.1.1

1.1.1.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Stuart Wilson

26/01 2016

1.1.0

1.1.0.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php ~5.5

 

by Stuart Wilson

21/08 2015

1.0.3

1.0.3.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php ~5.5

 

by Stuart Wilson

12/03 2015

1.0.2

1.0.2.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

The Requires

  • php ~5.5

 

by Stuart Wilson

27/12 2014

1.0.1

1.0.1.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

by Stuart Wilson

27/12 2014

1.0

1.0.0.0

PHP implementation of the Strava V3 API

  Sources   Download

MIT

by Stuart Wilson

04/09 2014

0.1

0.1.0.0 https://github.com/iamstuartwilson/strava

Simple PHP Library for the Strava v3 API

  Sources   Download

The Requires

  • php >=5.3