PHP code example of jordanpartridge / strava-client
1. Go to this page and download the library: Download jordanpartridge/strava-client 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/ */
jordanpartridge / strava-client example snippets
use JordanPartridge\StravaClient\Contracts\HasStravaToken;
use JordanPartridge\StravaClient\Concerns\HasStravaTokens;
class User extends Authenticatable implements HasStravaToken
{
use HasStravaTokens;
}
use JordanPartridge\StravaClient\Facades\StravaClient;
// Clean, intuitive API for fetching activities
$activities = StravaClient::activityForAthlete(page: 1, per_page: 10);
// Direct access to specific activities
$activity = StravaClient::getActivity($activityId);
use JordanPartridge\StravaClient\Exceptions\Request\BadRequestException;
use JordanPartridge\StravaClient\Exceptions\Request\RateLimitExceededException;
use JordanPartridge\StravaClient\Exceptions\Request\ResourceNotFoundException;
use JordanPartridge\StravaClient\Exceptions\Request\StravaServiceException;
try {
$activity = StravaClient::getActivity($id);
} catch (BadRequestException $e) {
// Handle malformed requests
} catch (RateLimitExceededException $e) {
// Handle API rate limits
} catch (ResourceNotFoundException $e) {
// Handle missing activities
} catch (StravaServiceException $e) {
// Handle server errors (500, 502, 504)
}
use App\Jobs\SyncStravaActivities;
try {
$activities = StravaClient::activityForAthlete(1, 50);
} catch (\RuntimeException $e) {
if (str_contains($e->getMessage(), 'service unavailable')) {
// Retry in 15 minutes
SyncStravaActivities::dispatch($user)->delay(now()->addMinutes(15));
}
}
try {
$activity = StravaClient::getActivity($id);
} catch (\RuntimeException $e) {
if ($e->getCode() === 503) {
return back()->with('error', 'Strava is temporarily unavailable. Please try again in a few minutes.');
}
}
bash
php artisan strava-client:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.