A wrapper for consume the Spotify Web API.
The authentication method should be refactored. The api used in the authorization is only for server-side request, and ajax requests do not work
For correct operation, I recommend using CORS Domain extensions.
CORS Everywhere for Firefox
Allow-Control-Allow-Origin: * for Chrome
This library relies on Fetch API. And this API is supported in the following browsers.
39+ β | 42+ β | 29+ β | 10.1+ β | Nope β |
- js-cookie A simple, lightweight JavaScript API for handling browser cookies
This library depends on fetch to make requests to the Spotify Web API. For environments that don't support fetch, you'll need to provide a polyfill to browser or polyfill to Node.
$ npm install spotifood-wrapper --save
or
$ yarn add spotifood-wrapper
// to import a specific method
import Spotifood from 'spotifood-wrapper';
const spotify = new Spotifood({
clientID: 'YOUR_CLIENT_ID_HERE',
clientSecret: 'YOUR_CLIENT_SECRET_HERE'
});
// using method
spotifood.search.artists('Incubus');
const Spotifood = require('spotifood-wrapper');
const spotify = new Spotifood({
clientID: 'YOUR_CLIENT_ID_HERE',
clientSecret: 'YOUR_CLIENT_SECRET_HERE'
});
<!-- to import non-minified version -->
<script src="spotifood-wrapper.umd.js"></script>
<!-- to import minified version -->
<script src="spotifood-wrapper.umd.min.js"></script>
After that the library will be available to the Global as Spotifood
. Follow an example:
const spotify = new Spotifood({
clientID: 'YOUR_CLIENT_ID_HERE',
clientSecret: 'YOUR_CLIENT_SECRET_HERE'
});
const albums = spotifood.search.albums('Choosen Artist');
Follow the methods that the library provides.
Search for informations about Albums with provided query. Test in Spotify Web Console with type defined as album.
Arguments
Argument | Type | Options |
---|---|---|
filters |
Object | An object filters |
locale |
String | A locale code |
country |
String | A country code |
timestamp |
String | A timestamp |
offset |
String | Limit of items |
- All params is optionals
Example
const filters = {
locale: 'pt_BR',
country: 'BR',
timestamp: '',
offset: 2
};
spotifood.browse.featuredPlaylists(filters)
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
spotifood.search.albums('Incubus')
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
spotifood.search.artists('Incubus')
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
spotifood.search.tracks('Drive')
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
spotifood.search.playlists('Happy Day')
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
id |
string | 'Specific id' |
Example
spotifood.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTy')
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
ids |
Array of strings | ['id1', 'id2'] |
Example
spotifood.album.getAlbums(['4aawyAB9vmqN3uQ7FjRGTy', '1A2GTWGtFfWp7KSQTwWOyo'])
.then(data => {
// do what you want with the data
})
Arguments
Argument | Type | Options |
---|---|---|
id |
string | 'Specific id' |
Example
spotifood.album.getTracks('4aawyAB9vmqN3uQ7FjRGTy')
.then(data => {
// do what you want with the data
})
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
Mateus Santana |
This project is licensed under the MIT License - see the LICENSE.md file for details