PHPackages                             rgjoni/spotify-web-api-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. rgjoni/spotify-web-api-sdk

ActiveLibrary[API Development](/categories/api)

rgjoni/spotify-web-api-sdk
==========================

Spotify Web API SDK for PHP

v1.1.0(4y ago)104GPL-3.0-onlyPHPPHP &gt;=8

Since May 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/MatrixEternal/spotify-web-api-sdk)[ Packagist](https://packagist.org/packages/rgjoni/spotify-web-api-sdk)[ RSS](/packages/rgjoni-spotify-web-api-sdk/feed)WikiDiscussions main Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

[![GitHub](https://camo.githubusercontent.com/b6c6bf0e495f5a3e2761777559c40c46ba0fef48dc5ef661ec1f449d8f7870f7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f5265617264476a6f6e692f73706f746966792d7765622d6170692d73646b3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/b6c6bf0e495f5a3e2761777559c40c46ba0fef48dc5ef661ec1f449d8f7870f7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f5265617264476a6f6e692f73706f746966792d7765622d6170692d73646b3f7374796c653d666c61742d737175617265)[![GitHub](https://camo.githubusercontent.com/9f7be7f0b81fd52023b94516b669d94f050cacf5b9b2cb3ed8218bc1d94ea9df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f5265617264476a6f6e692f73706f746966792d7765622d6170692d73646b3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9f7be7f0b81fd52023b94516b669d94f050cacf5b9b2cb3ed8218bc1d94ea9df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f5265617264476a6f6e692f73706f746966792d7765622d6170692d73646b3f7374796c653d666c61742d737175617265)[![packagist](https://camo.githubusercontent.com/aca6db3c6021e533ee291432267fec6c525e388ca2e892c52e502822da86c52d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72676a6f6e692f73706f746966792d7765622d6170692d73646b3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/aca6db3c6021e533ee291432267fec6c525e388ca2e892c52e502822da86c52d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72676a6f6e692f73706f746966792d7765622d6170692d73646b3f7374796c653d666c61742d737175617265)[![GitHub](https://camo.githubusercontent.com/d79f2e4ed8b0f5dbf8cd59f4ab802f954c4b4d4cdf06640e780a4b12922f7ed9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f5265617264476a6f6e692f73706f746966792d7765622d6170692d73646b2f6d61696e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d79f2e4ed8b0f5dbf8cd59f4ab802f954c4b4d4cdf06640e780a4b12922f7ed9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f5265617264476a6f6e692f73706f746966792d7765622d6170692d73646b2f6d61696e3f7374796c653d666c61742d737175617265)

Spotify Web API SDK
===================

[](#spotify-web-api-sdk)

An SDK for the Spotify Web API, covering all available endpoints and offering different authorization flows.

[ Reference link ](https://developer.spotify.com/documentation/web-api/reference/) (external) ### Table of contents

[](#table-of-contents)

1. [Supported API's](#supported-apis)
2. [Supported authorization flows](#supported-authorization-flows)
3. [Dependencies](#dependencies)
    1. [Development dependencies](#development-dependencies)
4. [Installation](#installation)
5. [Namespace](#namespace)
6. [Usage](#usage)

    1. [First Steps](#first-steps)
    2. [Authorization](#authorization)
        1. [Authorization Code Flow](#authorization-code-flow)
        2. [Authorization Code Flow with Proof Key for Code Exchange(PKCE)](#authorization-code-flow-with-proof-key-for-code-exchangepkce)
        3. [Client Credentials Flow](#client-credentials-flow)
        4. [Persisting tokens](#persisting-tokens)
    3. [Web API Endpoints](#web-api-endpoints)
7. [Errors &amp; Exceptions](#errors-&-exceptions)
8. [Contributing](#contributing)
9. [License](#license)

Supported API's
---------------

[](#supported-apis)

- Search API
- Browse API
- Follow API
- Playlists API
- Library API
- Artists API
- Player API
- Markets API
- Personalization API
- User Profile API
- Albums API
- Tracks API
- Episodes API
- Shows API

Supported authorization flows
-----------------------------

[](#supported-authorization-flows)

- Authorization Code
- Authorization Code with Proof Key for Code Exchange(PKCE)
- Client Credentials

Dependencies
------------

[](#dependencies)

- PHP 8.0 or higher
- Guzzle

### Development dependencies

[](#development-dependencies)

- PHPUnit

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

[](#installation)

Using composer:

```
composer require rgjoni/spotify-web-api-sdk

```

Namespace
---------

[](#namespace)

```
Gjoni\SpotifyWebApiSdk

```

Usage
-----

[](#usage)

### First steps

[](#first-steps)

Firstly, create a main Sdk object with the client credentials(client id, client secret), scopes and the redirect uri. For the credentials, you have to create an app on the [developer dashboard](https://developer.spotify.com/dashboard/).

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk;

# The scopes your app would need.
$scopes = [
    "user-read-private",
    "user-read-email",
    "playlist-read-private",
    "playlist-modify-public",
    "playlist-modify-private",
    "ugc-image-upload",
];
$redirectUri = "https://my.frontend.io/redirect";

$sdk = new SpotifyWebApiSdk\Sdk("clientId", "clientSecret", $scopes, $redirectUri);
```

### Authorization

[](#authorization)

After having created the main sdk object, these are the different ways to authorize your App to act on behalf of a user.

#### Authorization Code Flow

[](#authorization-code-flow)

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk\Authorization;

$authorization = new Authorization\AuthorizationCode($sdk);

# Build the URL and have your frontend make a GET request to it.
$url = $authorization->buildUrl();

# After this, you should have an authorization code; use it in another request
# to seek access to user resources.
$accessToken = $authorization->requestAccessToken("auth_code");

# When the access token expires, just refresh it
$newAccessToken = $authorization->refreshAccessToken("refresh_token");

# That's it!
```

#### Authorization Code Flow with Proof Key for Code Exchange(PKCE)

[](#authorization-code-flow-with-proof-key-for-code-exchangepkce)

1. Generate code verifier &amp; challenge, persist the verifier and build the url.

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk\Authorization;

$authorization = new Authorization\AuthorizationCodePKCE($sdk);

# Generate a code verifier and a code challenge based on it
$verifier = $authorization->generateCodeVerifier();
$challenge = $authorization->generateCodeChallenge($verifier);

# Set the code challenge, it will be needed in the next step
$authorization->setCodeChallenge($challenge);

# Have some way to persist the code verifier, it will be needed in the second request.
$cookie = new Cookie($this->cookieConfig);

if (empty($cookie->code_verifier)) {
    $cookie->code_verifier = $verifier;
}

# Build the URL and have your frontend make a GET request to it.
$url = $authorization->buildUrl();
```

2. After getting an authorization code on behalf of the end-user, seek access.

```
use Gjoni\SpotifyWebApiSdk\Authorization;

$cookie = new Cookie($this->cookieConfig);
$authorization = new Authorization\AuthorizationCodePKCE($this->sdk);

# Get the code verifier from your persistence method, in this case, a cookie
if (!empty($_COOKIE["code_verifier"])) {
    $authorization->setCodeVerifier($_COOKIE["code_verifier"]);
}

# Get your authorization code
$authCode = "my-auth-code";

# Request access
$accessToken = $authorization->requestAccessToken($authCode);

# When needed, refresh access
$newAccessToken = $authorization->refreshAccessToken("refresh-token");

# That's it!
```

#### Client Credentials Flow

[](#client-credentials-flow)

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk\Authorization;

$authorization = new Authorization\ClientCredentials($sdk);

# Directly seek access
$accessToken = $authorization->requestAccessToken();

# That's it!
```

#### Persisting tokens

[](#persisting-tokens)

This SDK does not offer tokens persistence(access &amp; refresh token), so that responsibility falls on the consuming project. In the examples in this README, cookie storage is used; but it's not the only possibility, read [this](https://stackoverflow.com/questions/44324080/how-to-store-access-token-oauth-2-auth-code-flow)&amp; [this](https://security.stackexchange.com/questions/113296/where-should-i-store-oauth2-access-tokens)(external links) for more information.

### Web API Endpoints

[](#web-api-endpoints)

Now that you have successfully authorized your App and persisted your tokens, now's the time to have some fun and request some user data!

#### Current user's profile

[](#current-users-profile)

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk\UsersProfile;

$usersProfile = new UsersProfile($sdk);

$usersProfile->me();
```

#### A public user's profile

[](#a-public-users-profile)

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk\UsersProfile;

$usersProfile = new UsersProfile($sdk);

# For a user with the id of 'wizzler'
$usersProfile->getUserProfile("wizzler");
```

The latter outputs the following JSON response:

```
{
  "data": {
    "display_name": "Ronald Pompa",
    "external_urls": {
      "spotify": "https://open.spotify.com/user/wizzler"
    },
    "followers": {
      "href": null,
      "total": 4032
    },
    "href": "https://api.spotify.com/v1/users/wizzler",
    "id": "wizzler",
    "images": [
      {
        "height": null,
        "url": "https://i.scdn.co/image/ab6775700000ee85b5d374d281b9e510eda15fdf",
        "width": null
      }
    ],
    "type": "user",
    "uri": "spotify:user:wizzler"
  }
}
```

#### Get a single artist

[](#get-a-single-artist)

```
require '/path/to/vendor/autoload.php';

use Gjoni\SpotifyWebApiSdk\Artists;

$artists = new Artists($sdk);

# For an artist with the id of '0OdUWJ0sBjDrqHygGUXeCF'(Band of Horses)
$artists->getSingle("0OdUWJ0sBjDrqHygGUXeCF");
```

This outputs the following JSON response:

```
{
  "data": {
    "external_urls": {
      "spotify": "https://open.spotify.com/artist/0OdUWJ0sBjDrqHygGUXeCF"
    },
    "followers": {
      "href": null,
      "total": 873614
    },
    "genres": [
      "indie folk",
      "indie pop",
      "indie rock",
      "modern rock",
      "stomp and holler"
    ],
    "href": "https://api.spotify.com/v1/artists/0OdUWJ0sBjDrqHygGUXeCF",
    "id": "0OdUWJ0sBjDrqHygGUXeCF",
    "images": [
      {
        "height": 640,
        "url": "https://i.scdn.co/image/0f9a5013134de288af7d49a962417f4200539b47",
        "width": 640
      },
      {
        "height": 320,
        "url": "https://i.scdn.co/image/8ae35be1043f330173de198c35a49161337e829c",
        "width": 320
      },
      {
        "height": 160,
        "url": "https://i.scdn.co/image/602dd7b3a2ee3f3fd86c6c4f50ab9b5a82e23c59",
        "width": 160
      }
    ],
    "name": "Band of Horses",
    "popularity": 65,
    "type": "artist",
    "uri": "spotify:artist:0OdUWJ0sBjDrqHygGUXeCF"
  }
}
```

Errors &amp; Exceptions
-----------------------

[](#errors--exceptions)

If you make an API request when the access token has expired, the following exception will be thrown:

```
Gjoni\SpotifyWebApiSdk\Exception\AccessTokenExpiredException

```

with the message:

```
The access token has expired, please refresh the token.

```

and the error code `401`.

Other, usage errors, such as not providing the right parameter or the wrong amount of them, will cause the `GuzzleHttp\Exception\RequestException` to bubble up to the top, necessitating to be handled by the project.

Contributing
------------

[](#contributing)

Pull requests and issues are welcome, please refer to [CONTRIBUTORS.md](docs/CONTRIBUTORS.md)

License
-------

[](#license)

[GPLv3](LICENSE.md)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~54 days

Total

4

Last Release

1650d ago

PHP version history (2 changes)v1.0.0PHP &gt;7.4

v1.0.1PHP &gt;=8

### Community

Maintainers

![](https://www.gravatar.com/avatar/98896d6a6894d85024c4c4cc7432d619b82473c079549845b546642243a53c7f?d=identicon)[rgjoni96](/maintainers/rgjoni96)

---

Top Contributors

[![IcyDrae](https://avatars.githubusercontent.com/u/35934418?v=4)](https://github.com/IcyDrae "IcyDrae (189 commits)")

---

Tags

phpspotify-web-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rgjoni-spotify-web-api-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/rgjoni-spotify-web-api-sdk/health.svg)](https://phpackages.com/packages/rgjoni-spotify-web-api-sdk)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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