PHPackages                             kirilkirkov/spotify-webapi-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. [HTTP &amp; Networking](/categories/http)
4. /
5. kirilkirkov/spotify-webapi-sdk

ActiveLibrary[HTTP &amp; Networking](/categories/http)

kirilkirkov/spotify-webapi-sdk
==============================

Spotify WebApi PHP Library

1.3(4y ago)173698MITPHPPHP &gt;=7.2.0

Since Mar 14Pushed 2y ago3 watchersCompare

[ Source](https://github.com/kirilkirkov/Spotify-WebApi-PHP-SDK)[ Packagist](https://packagist.org/packages/kirilkirkov/spotify-webapi-sdk)[ Fund](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7U9TVUV3URTK6&source=url)[ RSS](/packages/kirilkirkov-spotify-webapi-sdk/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

PHP SDK For Spotify Web Api
===========================

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

[![Spotify PHP](https://raw.githubusercontent.com/kirilkirkov/Spotify-WebApi-PHP-SDK/master/.github/logo%402x.png)](https://raw.githubusercontent.com/kirilkirkov/Spotify-WebApi-PHP-SDK/master/.github/logo%402x.png)

requires php &gt;= 7.2

- Integrated Pagination
- Automated Token Refresh
- Separate Services Files For All Api References
- Guzzle Requests

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

[](#installation)

composer require kirilkirkov/spotify-webapi-sdk

Example usage with code:

Doesnt have token?
------------------

[](#doesnt-have-token)

### Option 1 - Get access token with client credentials

[](#option-1---get-access-token-with-client-credentials)

```
use SpotifyWebAPI\SpotifyWebApi;

try {
    $spotifyWebApi = new SpotifyWebApi();
    $token_obj = $spotifyWebApi->getAccessTokenWithCredentials(
        'CLIENT_ID',
        'CLIENT_SECRET'
    );
    echo $token_obj->access_token;
    // echo $token_obj->token_type;
    // echo $token_obj->expires_in;
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
    echo $e->getMessage();
}

```

### Option 2 - Get access token with code authorization (recommended)

[](#option-2---get-access-token-with-code-authorization-recommended)

Before make requests you must add yours Redirect URIs to

Get redirect url for code:

```
use SpotifyWebAPI\SpotifyWebApi;

try {
    $spotifyWebApi = new SpotifyWebApi([
        'clientId' => 'CLIENT_ID',
        'clientSecret' => 'CLIENT_SECRET',
    ]);

    $callBackUrl = 'http://yoursite.com/callback';
    $url = $spotifyWebApi->getUrlForCodeToken($callBackUrl);
    header("Location: {$url}");
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
    echo $e->getMessage();
}

```

After signup in spotify you will be redirected back to provided above callback url () with parameter **$\_GET\['code'\]** with the code that can get token with following command:

```
use SpotifyWebAPI\SpotifyWebApi;

try {
    $spotifyWebApi = new SpotifyWebApi();
    $tokens = $spotifyWebApi->getAccessTokenWithCode(
        'YOUR_CODE',
        'http://yoursite.com/callback'
    );
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
    echo $e->getMessage();
}

```

And you will receive array with *accessToken* and *refreshToken* in the example above **$tokens**.

### Access/Refresh Tokens

[](#accessrefresh-tokens)

Spotify tokens are valid 1 hour. If your token is expired and you make a call, the sdk auto renew access token with provided refresh token in every query (as there is no safe place to automatically save it).

If you set $spotifyWebApi-&gt;returnNewTokenIfIsExpired(true); before your request calls, if access token is expired will be returned from the query, object with the new access\_token, then you can save it in database and recall request with a fresh Access token. You can also generate access token with refresh token manually with

```
use SpotifyWebAPI\SpotifyWebApi;

try {
    $spotifyWebApi = new SpotifyWebApi([
        'clientId' => 'CLIENT_ID',
        'clientSecret' => 'CLIENT_SECRET',
        'accessToken' => $oldAccessToken,
        'refreshToken' => 'REFRESH_TOKEN',
    ]);
    $result = $spotifyWebApi->refreshAccessToken();
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
    echo $e->getMessage();
}

```

and save final expire timestamp with time() + $result-&gt;expires\_in. You can manualy generate new access token every time when saved in your database expired time is end.

### Suggestions

[](#suggestions)

It is good practise to add ip of the api that you call in the hosts file in yours server os because Guzzle sometime cannot resolve the dns.

Can increase your execution time of scripts ini\_set('max\_execution\_time', XXX); and set\_time\_limit(XXX);

### Functions

[](#functions)

In the wiki of this repository you can find all functions available in this sdk (all the ones supported by Spotify have been integrated so far)

-
-  Integrated Pagination Example

Donate
------

[](#donate)

If this project help you reduce time to develop, you can give me a cup of coffee to continue its development. Thank you! :)

[![Donate](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.com/donate/?hosted_button_id=7U9TVUV3URTK6)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity53

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 ~357 days

Total

3

Last Release

1532d ago

### Community

Maintainers

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

---

Top Contributors

[![kirilkirkov](https://avatars.githubusercontent.com/u/3421328?v=4)](https://github.com/kirilkirkov "kirilkirkov (58 commits)")

---

Tags

guzzlephp-sdksdkspotifyspotify-apispotify-api-wrapperspotify-connectspotify-libraryspotify-phpspotify-pluginspotify-sdkspotify-web-apispotify-web-api-laravelspotify-web-api-phpspotify-web-sdkspotifyspotify-apispotify-web-apispotify-php-sdk

### Embed Badge

![Health badge](/badges/kirilkirkov-spotify-webapi-sdk/health.svg)

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

###  Alternatives

[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[aerni/laravel-spotify

A Laravel wrapper for the Spotify Web API

209145.6k](/packages/aerni-laravel-spotify)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)[meteocontrol/vcom-api-client

HTTP Client for meteocontrol's VCOM API - The VCOM API enables you to directly access your data on the meteocontrol platform.

175.7k1](/packages/meteocontrol-vcom-api-client)

PHPackages © 2026

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