PHP code example of basvandorst / stravaphp

1. Go to this page and download the library: Download basvandorst/stravaphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

basvandorst / stravaphp example snippets



include 'vendor/autoload.php';

use Strava\API\OAuth;
use Strava\API\Exception;

try {
    $options = [
        'clientId'     => 1234,
        'clientSecret' => 'APP-TOKEN',
        'redirectUri'  => 'http://my-app/callback.php'
    ];
    $oauth = new OAuth($options);

    if (!isset($_GET['code'])) {
        print '<a href="'.$oauth->getAuthorizationUrl([
            // Uncomment         'code' => $_GET['code']
        ]);
        print $token->getToken();
    }
} catch(Exception $e) {
    print $e->getMessage();
}


Strava\API\Client;
use Strava\API\Exception;
use Strava\API\Service\REST;

try {
    $adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3/']);
    $service = new REST($token->getToken(), $adapter);  // Define your user token here.
    $client = new Client($service);

    $athlete = $client->getAthlete();
    print_r($athlete);

    $activities = $client->getAthleteActivities();
    print_r($activities);

    $club = $client->getClub(9729);
    print_r($club);
} catch(Exception $e) {
    print $e->getMessage();
}

use Strava\API\Factory;

// Configure your app ID, app token and callback uri
$factory = new Factory();
$OAuthClient = $factory->getOAuthClient(1234, 'APP-TOKEN', 'http://my-app/callback.php');

$factory->getOAuthClient($client_id, $client_secret, $redirect_uri);
$factory->getAPIClient($token);

use Strava\API\OAuth;

// Parameter information: https://strava.github.io/api/v3/oauth/#get-authorize
$options = [
    'clientId'     => 1234,
    'clientSecret' => 'APP-TOKEN',
    'redirectUri'  => 'http://my-app/callback.php'
];
$oauth = new OAuth($options);

// The OAuth authorization procces (1st; let the user approve, 2nd; token exchange with Strava)
if (!isset($_GET['code'])) {
    print '<a href="'.$oauth->getAuthorizationUrl([
        // Uncomment 

$oauth->getAuthorizationUrl($options = []);
$oauth->getAccessToken($grant = 'authorization_code', $params = []);

// REST adapter (We use `Guzzle` in this project)
use GuzzleHttp\Client as GuzzleClient;
use Strava\API\Service\REST;
use Strava\API\Client;

$adapter = new GuzzleClient(['base_uri' => 'https://www.strava.com/api/v3/']);
// Service to use (Service\Stub is also available for test purposes)
$service = new REST('RECEIVED-TOKEN', $adapter);

// Receive the athlete!
$client = new Client($service);
$athlete = $client->getAthlete();
print_r($athlete);

$client->getAthlete($id = null);
$client->getAthleteStats($id);
$client->getAthleteClubs();
$client->getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null);
$client->getAthleteActivities($before = null, $after = null, $page = null, $per_page = null);
$client->getAthleteFriends($id = null, $page = null, $per_page = null);
$client->getAthleteFollowers($id = null, $page = null, $per_page = null);
$client->getAthleteBothFollowing($id, $page = null, $per_page = null);
$client->getAthleteKom($id, $page = null, $per_page = null);
$client->getAthleteZones();
$client->getAthleteStarredSegments($id = null, $page = null, $per_page = null);
$client->updateAthlete($city, $state, $country, $sex, $weight);
$client->getActivityFollowing($before = null, $page = null, $per_page = null); 
$client->getActivity($id, $($id);
$client->getClubMembers($id, $page = null, $per_page = null);
$client->getClubActivities($id, $page = null, $per_page = null);
$client->getRoute($id);
$client->getRouteAsGPX($id);
$client->getRouteAsTCX($id);
$client->getSegment($id);
$client->getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $page = null, $per_page = null);
$client->getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null);
$client->getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null);
$client->getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance');
$client->getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance');
$client->getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance');
$client->getStreamsRoute($id);