Giter Site home page Giter Site logo

campaignamp / spotify-web-api-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jwilsson/spotify-web-api-php

0.0 2.0 0.0 566 KB

A PHP implementation of Spotify's Web API.

Home Page: https://jwilsson.github.io/spotify-web-api-php/

License: MIT License

PHP 100.00%

spotify-web-api-php's Introduction

Spotify Web API PHP

Build Status Coverage Status Latest Stable Version

This is a PHP implementation of the Spotify Web API. It includes the following:

  • Helper methods for all API methods:
    • Information about artists, albums, tracks, and users.
    • Spotify catalog search.
    • Playlist and user music library management.
    • Music featured by Spotify.
  • Authorization flow helpers.
  • PSR-4 autoloading support.

Requirements

Installation

Add spotify-web-api-php as a dependency to your composer.json:

"require": {
    "jwilsson/spotify-web-api-php": "^1.0.0"
}

For more instructions, please refer to the documentation.

Examples

Add tracks to a user's library

$api->addMyTracks(array('1oR3KrPIp4CbagPa3PhtPp', '6lPb7Eoon6QPbscWbMsk6a'));

Add tracks to a user's playlist

$api->addUserPlaylistTracks('username', 'playlist_id', array(
    '1oR3KrPIp4CbagPa3PhtPp',
    '6lPb7Eoon6QPbscWbMsk6a'
));

Create a new playlist for a user

$api->createUserPlaylist('username', array(
    'name' => 'My shiny playlist'
));

Check if the current user follows a user or artist

$follows = $api->currentUserFollows('user', array(
    'spotify',
    'spotify_france'
));

var_dump($follows);

Delete tracks from a user's library

$api->deleteMyTracks(array(
    '1oR3KrPIp4CbagPa3PhtPp',
    '6lPb7Eoon6QPbscWbMsk6a'
));

Delete tracks from a user's playlist

$tracks = array(
    array('id' => '1oR3KrPIp4CbagPa3PhtPp'),
    array('id' => '6lPb7Eoon6QPbscWbMsk6a')
);

$api->deleteUserPlaylistTracks('username', 'playlist_id', $tracks, 'snapshot_id');

Follow an artist or user

$api->followArtistsOrUsers('artist', array(
    '74ASZWbe4lXaubB36ztrGX',
    '2t9yJDJIEtvPmr2iRIdqBf'
));

Follow a playlist

$api->followPlaylist('username', 'playlist_id');

Get a album

$album = $api->getAlbum('7u6zL7kqpgLPISZYXNTgYk');

print_r($album);

Get multiple albums

$albums = $api->getAlbums(array(
    '1oR3KrPIp4CbagPa3PhtPp',
    '6lPb7Eoon6QPbscWbMsk6a'
));

print_r($albums);

Get all tracks from an album

$tracks = $api->getAlbumTracks('1oR3KrPIp4CbagPa3PhtPp');

print_r($tracks);

Get an artist

$artist = $api->getArtist('36QJpDe2go2KgaRleHCDTp');

print_r($artist);

Get an artist's related artists

$artists = $api->getArtistRelatedArtists('36QJpDe2go2KgaRleHCDTp');

print_r($artists);

Get multiple artists

$artists = $api->getArtists(array(
    '6v8FB84lnmJs434UJf2Mrm',
    '6olE6TJLqED3rqDCT0FyPh'
));

print_r($artists);

Get all albums by an artist

$albums = $api->getArtistAlbums('6v8FB84lnmJs434UJf2Mrm');

print_r($albums);

Get an artist's top tracks in a country

$tracks = $api->getArtistTopTracks('6v8FB84lnmJs434UJf2Mrm', array(
    'country' => 'se'
));

print_r($tracks);

Get Spotify featured playlists

$playlists = $api->getFeaturedPlaylists();

print_r($playlists);

Get Spotify list of categories

$categories = $api->getCategoriesList(array(
    'country' => 'se'
));

print_r($categories);

Get Spotify category

$category = $api->getCategory('dinner', array(
    'country' => 'se'
));

print_r($category);

Get playlists of a Spotify category

$playlists = $api->getCategoryPlaylists('dinner', array(
    'country' => 'se'
));

print_r($playlists);

Get new releases

$items = $api->getNewReleases(array(
    'country' => 'se'
));

print_r($items);

Get a user's saved tracks

$tracks = $api->getMySavedTracks();

print_r($tracks);

Get a track

$track = $api->getTrack('7EjyzZcbLxW7PaaLua9Ksb');

print_r($track);

Get multiple tracks

$tracks = $api->getTracks(array(
    '0eGsygTp906u18L0Oimnem',
    '1lDWb6b6ieDQ2xT7ewTC3G'
));

print_r($tracks);

Get a user

$user = $api->getUser('username');

print_r($user);

Get user's playlists

$playlists = $api->getUserPlaylists('username');

print_r($playlists);

Get a specific playlist

$playlist = $api->getUserPlaylist('username', '606nLQuR41ZaA2vEZ4Ofb8');

print_r($playlist);

Get all tracks in a user's playlist

$tracks = $api->getUserPlaylistTracks('username', '606nLQuR41ZaA2vEZ4Ofb8');

print_r($tracks);

Get the currently authenticated user

$user = $api->me();

print_r($user);

See if a user's tracks contains the specified tracks

$contains = $api->myTracksContains(array(
    '0eGsygTp906u18L0Oimnem',
    '1lDWb6b6ieDQ2xT7ewTC3G'
));

var_dump($contains);

Reorder the tracks in a user's playlist

$api->reorderUserPlaylistTracks('username', 'playlist_id', array(
    'range_start' => 1,
    'range_length' => 5,
    'insert_before' => 10,
    'snapshot_id' => 'GLiKqjND5IDWQCO9PwtLvHVjRXYYjEvpoliIQ5/gK7M5BMcxJ7rnGMGTKbmDRgU3'
));

Replace all tracks in a user's playlist with new ones

$api->replaceUserPlaylistTracks('username', 'playlist_id', array(
    '0eGsygTp906u18L0Oimnem',
    '1lDWb6b6ieDQ2xT7ewTC3G'
));

Search for an album

$albums = $api->search('blur', 'album');

print_r($albums);

Search for an artist

$artists = $api->search('blur', 'artist');

print_r($artists);

Search for a track

$tracks = $api->search('song 2', 'track');

print_r($tracks);

Search with a limit

$tracks = $api->search('song 2', 'track', array(
    'limit' => 5
));

print_r($tracks);

Search for tracks in a specific market

$tracks = $api->search('song 2', 'track', array(
    'market' => 'se'
));

print_r($tracks);

Update a user's playlist

$api->updateUserPlaylist('username', 'playlist_id', array(
    'name' => 'New name'
));

Unfollow an artist or user

$api->unfollowArtistsOrUsers('user', array(
    'spotify',
    'spotify_france'
));

Unfollow a playlist

$api->unfollowPlaylist('username', 'playlist_id');

Check if a user is following a playlist

$users = array(
    'user1',
    'user2'
);

$api->userFollowsPlaylist('owner_id', 'playlist_id', array(
    'ids' => $users
));

For more examples, please see the homepage.

License

MIT license. Please see LICENSE.md for more information.

spotify-web-api-php's People

Contributors

benlumley avatar bluemath avatar disup avatar hvt avatar jmperez avatar jwilsson avatar thebabayaga avatar vdesabou avatar vorenuscoa avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.