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)163698MITPHPPHP &gt;=7.2.0CI failing

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 3w 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 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

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

1586d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3421328?v=4)[Kiril Kirkov](/maintainers/kirilkirkov)[@kirilkirkov](https://github.com/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

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[illuminate/http

The Illuminate Http package.

11937.9M6.8k](/packages/illuminate-http)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[guzzlehttp/guzzle-services

Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.

25711.0M189](/packages/guzzlehttp-guzzle-services)[aerni/laravel-spotify

A Laravel wrapper for the Spotify Web API

208163.7k](/packages/aerni-laravel-spotify)

PHPackages © 2026

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