Skip to content

This is a single-file-library that you can use to interrogate the Strava v3 API. It handles authentication as well as whatever API calls you want to me (as long as they are valid)

License

Notifications You must be signed in to change notification settings

DaveWilcock/php-strava-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Strava v3 API Client

This is a single-file-library that you can use to interrogate the Strava v3 API. It handles authentication as well as whatever API calls you want to make (as long as they are valid)

Usage

First off you need to construct a configuration array. The array should contain at least the following information:

  • CLIENT_ID
  • CLIENT_SECRET
  • REDIRECT_URI
  • ACCESS SCOPE

CLIENT_ID and CLIENT_SECRET should be taken from the My API Application section of the site. Valid ACCESS_SCOPE values can be found in the Strava API documentation

Optionally, you can supply the following addition configuration options:

  • CACHE_DIRECTORY
  • ACCESS_TOKEN

If CACHE_DIRECTORY isn't supplied, the library falls back to writing to /tmp

If ACCESS_TOKEN is supplied, we bypass authorization and token exchange - assuming the ACCESS_TOKEN is correct.

Examples

To configure the client, you would define your parameters as follows:

<?php
$arrConfig = array(
   'CLIENT_ID' => 1354,
   'CLIENT_SECRET' => 'here is my client secret',
   'REDIRECT_URI' => 'http://localhost/example.php',
   'CACHE_DIRECTORY' => '/path/to/cache/dir/',
   'ACCESS_SCOPE' => 'write'
);

The following example GETs information about the authenticated athlete:

<?php
$objStrava = new \dawguk\Strava($arrConfig);
print_r($objStrava->get('athlete', array()));

The following example PUTs (updates) the weight information for the current athlete:

<?php
$objStrava = new \dawguk\Strava($arrConfig);
print_r($objStrava->put('athlete', array('weight' => 62.8)));

Notes

Currently the library will only store a single access token, so isn't ready for multi-user authentication. This is expected to change in the future, with token storage abstracted out.

Now available on packagist.org ;D

References

http://strava.github.io/api/v3 is a good place to start.

About

This is a single-file-library that you can use to interrogate the Strava v3 API. It handles authentication as well as whatever API calls you want to me (as long as they are valid)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages