Spotify Api with client side authentication in angularjs with responsive layout . Lay out compatible with latest version of all browsers. Chrome, Firefox, Opera, IE, Edge, Safari
angular service to connect to the Spotify Web API
Responsive layout compatible with all sizes of device and all latest browsers
Chrome: 58
Firefox: 53
Safari: 10.1
Internet Explorer: 11
IE-Edge
Opera
Install angular-spotify via bower. Use the —save property to save into your bower.json file.
bower install angular-spotify --save
Also available on npm
npm install angular-spotify --save
Include spotify into your angular module
var app = angular.module('example', ['spotify']);
Spotify implement Authentication on all Api requests here I am using client base authentication. This token will be expire in 3600 milli second Replace this code with your code in main controller:
app.config(function (SpotifyProvider) {
SpotifyProvider.setClientId('<CLIENT_ID>');
SpotifyProvider.setRedirectUri('<CALLBACK_URI>');
SpotifyProvider.setScope('<SCOPE>');
// If you already have an auth token by using other authentication methods
SpotifyProvider.setAuthToken('<AUTH_TOKEN>');
});
For example:
app.config(function (SpotifyProvider) {
SpotifyProvider.setClientId('ABC123DEF456GHI789JKL');
SpotifyProvider.setRedirectUri('http://www.example.com/callback.html');
SpotifyProvider.setScope('user-read-private playlist-read-private playlist-modify-private playlist-modify-public');
// If you already have an auth token by using other authentication methods
SpotifyProvider.setAuthToken('zoasliu1248sdfuiknuha7882iu4rnuwehifskmkiuwhjg23');
});
Inject Spotify into a controller to gain access to all the functions available
app.controller('MainCtrl', function (Spotify) {
});
Will open login window. Requires user to initiate as it will open a pop up window.
Requires client id, callback uri and scope to be set in config.
Spotify.login();
Example:
$scope.login = function () {
Spotify.login();
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<script>
window.onload = function () {
var hash = window.location;
if (window.location.search.substring(1).indexOf("error") !== -1) {
// login failure
window.close();
} else if (hash) {
var token = window.location.hash.split('#')[1].split('=')[1].split('&')[0];
localStorage.setItem('spotify-token', token);
// login success
window.close();
}
};
</script>
</head>
<body>
</body>
</html>
Spotify.search('Query parameter', 'type').then(function (result)
Get list of Spotify artist .
Spotify.search('Query parameter', 'artist').then(function (result)
Get list of Spotify albums .
Spotify.search('Query parameter', 'album').then(function (result)
Get Spotify catalog information about an album’s tracks. Optional parameters can be used to limit the number of tracks returned.
Spotify.getAlbumTracks('AlbumID or Spotify Album URI', options);
Example:
Spotify.getAlbumTracks('6akEvsycLGftJxYudPjmqK').then(function (data) {
console.log(data);
});
Get Spotify catalog information about an artist’s albums. Optional parameters can be passed in to filter and sort the response.
Spotify.getArtistAlbums('Artist Id or Spotify Artist URI', options);
Example: { album_type: ‘album,single’ }
Example:
Spotify.getArtistAlbums('1vCWHaC5f2uS3yhpwWbIA6').then(function (data) {
console.log(data);
});