PHPackages                             goosfraba/strava-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. goosfraba/strava-sdk

ActiveLibrary[API Development](/categories/api)

goosfraba/strava-sdk
====================

Strava SDK for PHP

01PHP

Since Oct 2Pushed 2y ago2 watchersCompare

[ Source](https://github.com/dbojdo/strava-sdk)[ Packagist](https://packagist.org/packages/goosfraba/strava-sdk)[ RSS](/packages/goosfraba-strava-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Strava SDK
==========

[](#strava-sdk)

This packages provides high level SDK for Strava API

Installation
------------

[](#installation)

Install the package via *composer*

```
composer require goosfraba/strava-sdk
```

Usage
-----

[](#usage)

This sections shows how to use the SDK

### Request Access URL

[](#request-access-url)

The SDK provides a handy way to generate a request access URL (e.g. for Connect with Strava button).

```
use Goosfraba\StravaSDK\Access\RequestAccessUrl;
use Goosfraba\StravaSDK\Access\Scope;
use Goosfraba\StravaSDK\Access\ApprovalPrompt;

$url = (string)(new RequestAccessUrl(
    "231243", // your app client ID
    "https://your-app.com/strava/access-granted", // the callback URL
    [
        Scope::general(true), // general scope "read_all"
        Scope::profile(false), // profile resource scope "read"
        Scope::activity(false, true), // activity resource scope "read" and "write",
    ], // the list of the scopes, select whatever your app needs
    null, // optional: the state of your application (passed to your callback URL in query string)
    ApprovalPrompt::auto() // optional: the approval prompt mode, "auto" by default
));
```

### Authentication (Connect with Strava)

[](#authentication-connect-with-strava)

In order to use the API you need to utilise the *code* passed into your callback URL. Below you can find an example controller that handles the callback URL.

Disclaimer: This controller is for demo purpose only, to show how the flow and particular SDK components work. It's not in a production shape in any way.

```
use Goosfraba\StravaSDK\Auth\AuthApi;
use Goosfraba\StravaSDK\Auth\AuthApiFactory;
use Goosfraba\StravaSDK\Auth\ClientCredentials;

class StravaCallbackController
{
    private AuthApi $authApi;

    public function __construct(AuthApi $authApi)
    {
        $oAuthApiFactory = new AuthApiFactory();
        $this->authApi = $oAuthApiFactory->create(
            new ClientCredentials("your app id", "your app secret")
        );
    }

    /**
     *
     */
    public function accessGranted($request)
    {
        // "code" from the query string of the URL
        $tokenResponse = $this->authApi->authorise($request["code"]);

        // "state" from the query string of the callback URL
        $state = $request["state"]; // whatever was passed into the access request URL

        /**
         * The athlete that gave the permissions.
         * Link it with your user.
         */
        $athlete = $tokenResponse->athlete()

        /**
         * The OAuth token to be used in further queries.
         * Save it along with the user.
         */
        $oAuthToken = $tokenResponse->token();
    }
}
```

### OAuthApi

[](#oauthapi)

This API allows to authorize your app, refresh the access token and de-authorize your app.

#### Create the OAuthAPi

[](#create-the-oauthapi)

```
use Goosfraba\StravaSDK\Auth\AuthApiFactory;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Goosfraba\StravaSDK\Auth\ClientCredentials;

/**
 * The event dispatcher is an important component in the flow od the API usage.
 * The APIs support automatic token refresh, and you want to make sure you store the latest viable token.
 * More in the section "Automatic Token Refresh"
 */
$oAuthApiFactory = new AuthApiFactory();

$oAuthApi = $oAuthApiFactory->create(new ClientCredentials("your app id", "your app secret"));
```

#### Authorization

[](#authorization)

Authorization process generates an OAuth token and returns the athlete's details

```
/** @var \Goosfraba\StravaSDK\Auth\AuthApi $oAuthApi */
$code = "32443534safgfgsfgfssew3224323"; // the code from the callback URL
$tokenResponse = $oAuthApi->authorise($code);
$token = $tokenResponse->token();
$athlete = $tokenResponse->athlete();
```

#### De-authorization

[](#de-authorization)

De-authorization process unlinks your application from the athlete's Stava account

```
/** @var \Goosfraba\StravaSDK\Auth\AuthApi $oAuthApi */
/** @var \Goosfraba\StravaSDK\Auth\AuthToken $token */
$oAuthApi->deAuthorize($token);
```

#### Token refresh

[](#token-refresh)

Expired access token needs to be refreshed every now and then.

```
/** @var \Goosfraba\StravaSDK\Auth\AuthApi $oAuthApi */
/** @var \Goosfraba\StravaSDK\Auth\AuthToken $token */
$newToken = $oAuthApi->refreshToken($token);
```

#### Automatic token refresh

[](#automatic-token-refresh)

All the APIs support the automatic token refresh. You want to make sure you've got stored the latest viable token. In order to do this, you need to provide the `OAuthTokenCallback` implementation into the `OAuthApi`.

An example implementation:

```
use Goosfraba\StravaSDK\Auth\TokenCallback\OAuthTokenCallback;
use Goosfraba\StravaSDK\Auth\AuthToken;

final class YourAppOAuthTokenCallback implements OAuthTokenCallback
{
    private UserRepository $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function onAuthorise(string $code, AuthorisationResponse $tokenResponse): void
    {
        $user = new User(
            // fill up the data from the token response
        );
        $user->updateStravaToken($tokenResponse->token());

        $this->userRepository->save($user);
    }

    public function onDeAuthorise(AuthToken $token): void
    {
        $user = $this->userRepository->findByStravaToken($token);
        if (!$user) {
            return;
        }

        $user->deAuthoriseStrava();
        $this->userRepository->save($user);
    }

    public function onTokenRefresh(AuthToken $newToken, AuthToken $oldToken): void
    {
        $user = $this->userRepository->findByStravaToken($oldToken);
        $user->updateStravaToken($newToken);
        $this->userRepository->save($user);
    }
}
```

To register your token callback:

```
use Goosfraba\StravaSDK\Auth\AuthApiFactory;
/** @var UserRepositroy $userRepository */

$oAuthApiFactory = new AuthApiFactory(
    new YourAppOAuthTokenCallback($userRepository)
);
```

### ApiFactory component

[](#apifactory-component)

This component creates an instances of particular APIs.

```
use Goosfraba\StravaSDK\ApiFactory;use Goosfraba\StravaSDK\Auth\AuthToken;use Goosfraba\StravaSDK\Http\Buzz\AuthenticatedBrowserFactory;

$apiFactory = new ApiFactory(
    new AuthenticatedBrowserFactory(
        $oAuthApi,
        new AuthToken("refresh token", "access token")
    )
);
```

### AthletesApi

[](#athletesapi)

#### Create the AthletesApi

[](#create-the-athletesapi)

```
use Goosfraba\StravaSDK\ApiFactory;

/** @var ApiFactory $apiFactory */

$athletesApi = $apiFactory->athletesApi();
```

#### Supported operations

[](#supported-operations)

- **getAuthenticatedAthlete** - gets the details of the authenticated athlete

### ActivitiesApi

[](#activitiesapi)

#### Create the ActivitiesApi

[](#create-the-activitiesapi)

```
use Goosfraba\StravaSDK\ApiFactory;

/** @var ApiFactory $apiFactory */

$activitiesApi = $apiFactory->activitiesApi();
```

#### Supported operations

[](#supported-operations-1)

- **listAthleteActivities** - lists the activities of authenticated athlete
- **getActivity** - gets a single activity by its ID
- **createActivity** - creates a new activity
- **updateActivity** - updates an existing activity
- **listActivityComments** - lists the comments of given activity
- **listActivityKudoers** - lists the kudoers of given activity
- **listActivityLaps** - lists the laps of given activity
- **listActivityZones** - lists the zones of given activity

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a6cc50814a7b150c2a02d719d33c6e11040a6d0d010b2f986a24794edce7f52f?d=identicon)[dbojdo](/maintainers/dbojdo)

---

Top Contributors

[![dbojdo](https://avatars.githubusercontent.com/u/1272416?v=4)](https://github.com/dbojdo "dbojdo (1 commits)")

### Embed Badge

![Health badge](/badges/goosfraba-strava-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/goosfraba-strava-sdk/health.svg)](https://phpackages.com/packages/goosfraba-strava-sdk)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
