Download the PHP package aslamhus/spotify-client without Composer

On this page you can find all versions of the php package aslamhus/spotify-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package spotify-client

Spotify API Client (PHP)

Overview

This PHP package provides a simple and convenient way to interact with the Spotify API. It includes methods for making authenticated requests, retrieving resources, and performing searches. The class utilizes the GuzzleHttp library for HTTP requests.

Installation

Usage

Authorization

Authorization is required to access different scopes of Spotify resources. Choose between Client Credentials and Authorization Code.

Client Credentials

For server-to-server authentication you can use Spotify's Client Credentials authorization flow. Simply pass your client id and secret to a SpotifyAccessToken, then inject the token into a new Spotify instance. The client id and secret can be found in your Spotify Dashboard. For security, it is recommended to store your client id and secret in environment variables.

Note: User information (like playlists) cannot be accessed with these credentials

Authorization Code

The authorization code flow is suitable for long-running applications (e.g. web and mobile apps) where the user grants permission only once.

By requesting authorization from the user, you can gain access to different scopes of Spotify resources.

Please refer to the Spotify docs for more on the Authorization Code flow: https://developer.spotify.com/documentation/web-api/tutorials/code-flow

This authorization has a two step process:

  1. Request user authorization.

    Generate an authorization request url with the static method getAuthorizeUrl. Once the user is directed to this url, they will be prompted to give permissions to the scopes you specified. Once they grant permission, they will be redirected to the redirect uri you specified.

    Find a list of Spotify API scopes here.

    Note that the redirect uri must be set in your application's dashboard.

    When the user is redirected to the uri you have specified, save the code string from the query parameter.

  2. Request access token

    You are now ready to request an access token with the user's granted permissions. Create a new AuthorizationCode credentials object with the code and redirect uri from the previous step. This will generate an access token with the appropriate permissions.

    Note: the redirect uri passed to AuthorizationCode must match exactly the redirect uri you specified in your application's dashboard and in the previous step.

Stored Token

If you have saved a token to the database, you can create a new AccessToken and pass that to Spotify.

Token expiration and refresh tokens

Spotify tokens are intentionally set to expire after 1 hour. If you have used the AuthorizationCode credentials, your token comes with a refresh token. Aslamhus\Spotify will automatically handle refreshing your token when you make a request.

Get Resource

Search

Search results are paginated. When you perform a search, you can get a SearchResult object for each type you've searched for, i.e. 'artist, track, album' would return a separate SearchResult object for each type.

Note: Search is currently only available for tracks, albums and artists

Basic search

Using queries with special characters

There is scant documentation on how to format Spotify API searches, but tests show it is best to urlencode your queries. For instance, searching for the track "Home Cookin' by Cory Weeds" will return no results if not urlencoded.

Get Search Items

Search Result Types

Each SearchResult object contains an array of search items. Depending on the given type you are searching for, each item in the array will be an entity object like Aritst or Album. If you are searching for tracks, instead of an array of Track objects, you will receieve the Tracks object, which functions like an array but with additional methods for managing and ssearching for tracks.

Get next results

Let's demonstrate how to get the next results. Each SearchResult object has a next method, which gets the next set of results if available. If there are no next results, next returns null.

Get all artist albums

Get all tracks for an album

Carrying on from the last example, we can now load the tracks any album.

Note that the data for entity objects like Album, Artist, and Track is lazy loaded. You have to explicitly fetch their data with the relevant get method.

Playlist

Get Playlist

IMPORTANT: Working with Playlist or User entities requires the AuthorizationCode credentials

This example assumes you know the id of the playlist.

Create a new playlist

The static method create is a factory function which returns a new instance of the Playlist entity.

Add Tracks

In order to add a track to a playlist you must know its track id. If you have previously loaded a Track or Tracks object with an id associated with it, you can simply add those.

Adding a single track

Adding a track to a specific index in the playlist

Adding multiple tracks

Remove Tracks

Unfollow a playlist

A note about deleting / unfollowing playlists from the Spotify API Docs:

"We have no endpoint for deleting a playlist in the Web API; the notion of deleting a playlist is not relevant within the Spotify’s playlist system. Even if you are the playlist’s owner and you choose to manually remove it from your own list of playlists, you are simply unfollowing it. Although this behavior may sound strange, it means that other users who are already following the playlist can keep enjoying it. Manually restoring a deleted playlist through the Spotify Accounts Service is the same thing as following one of your own playlists that you have previously unfollowed."

Additional playlist methods

Error Handling

If a non-200 status code is received, an exception is thrown with a descriptive error message.

Status Codes

The class includes a list of common Spotify API status codes along with descriptions for reference.

Contributing

Feel free to contribute by opening issues or submitting pull requests. Your feedback is valuable.

License

This package is open-source software licensed under the MIT License.


All versions of spotify-client with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/psr7 Version ^2.6
guzzlehttp/guzzle Version ^7.8
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aslamhus/spotify-client contains the following files

Loading the files please wait ....