项目作者: ahsankhan201

项目描述 :
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
高级语言: JavaScript
项目地址: git://github.com/ahsankhan201/spotify-angularJS.git
创建时间: 2017-06-10T06:47:05Z
项目社区:https://github.com/ahsankhan201/spotify-angularJS

开源协议:MIT License

下载


angular-spotify (Angular client side authentication- Sass - Responsive layout)

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

Usage

Install angular-spotify via bower. Use the —save property to save into your bower.json file.

  1. bower install angular-spotify --save

Also available on npm

  1. npm install angular-spotify --save

Include spotify into your angular module

  1. 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:

  1. app.config(function (SpotifyProvider) {
  2. SpotifyProvider.setClientId('<CLIENT_ID>');
  3. SpotifyProvider.setRedirectUri('<CALLBACK_URI>');
  4. SpotifyProvider.setScope('<SCOPE>');
  5. // If you already have an auth token by using other authentication methods
  6. SpotifyProvider.setAuthToken('<AUTH_TOKEN>');
  7. });

For example:

  1. app.config(function (SpotifyProvider) {
  2. SpotifyProvider.setClientId('ABC123DEF456GHI789JKL');
  3. SpotifyProvider.setRedirectUri('http://www.example.com/callback.html');
  4. SpotifyProvider.setScope('user-read-private playlist-read-private playlist-modify-private playlist-modify-public');
  5. // If you already have an auth token by using other authentication methods
  6. SpotifyProvider.setAuthToken('zoasliu1248sdfuiknuha7882iu4rnuwehifskmkiuwhjg23');
  7. });

Inject Spotify into a controller to gain access to all the functions available

  1. app.controller('MainCtrl', function (Spotify) {
  2. });

Authentication

Login

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.

  1. Spotify.login();

Example:

  1. $scope.login = function () {
  2. Spotify.login();
  3. };

Example callback html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title></title>
  7. <script>
  8. window.onload = function () {
  9. var hash = window.location;
  10. if (window.location.search.substring(1).indexOf("error") !== -1) {
  11. // login failure
  12. window.close();
  13. } else if (hash) {
  14. var token = window.location.hash.split('#')[1].split('=')[1].split('&')[0];
  15. localStorage.setItem('spotify-token', token);
  16. // login success
  17. window.close();
  18. }
  19. };
  20. </script>
  21. </head>
  22. <body>
  23. </body>
  24. </html>
  1. Spotify.search('Query parameter', 'type').then(function (result)

Get list of Spotify artist .

  1. Spotify.search('Query parameter', 'artist').then(function (result)

Get list of Spotify albums .

  1. Spotify.search('Query parameter', 'album').then(function (result)

Get an Album’s Tracks

Get Spotify catalog information about an album’s tracks. Optional parameters can be used to limit the number of tracks returned.

  1. Spotify.getAlbumTracks('AlbumID or Spotify Album URI', options);
Options Object (Optional)
  • limit - Optional. The maximum number of tracks to return. Default: 20. Minimum: 1. Maximum: 50.
  • offset - Optional. The index of the first track to return. Default: 0 (the first object). Use with limit to get the next set of tracks.

Example:

  1. Spotify.getAlbumTracks('6akEvsycLGftJxYudPjmqK').then(function (data) {
  2. console.log(data);
  3. });

Get an Artist’s Albums

Get Spotify catalog information about an artist’s albums. Optional parameters can be passed in to filter and sort the response.

  1. Spotify.getArtistAlbums('Artist Id or Spotify Artist URI', options);
Options Object (Optional)
  • album_type - Optional A comma-separated list of keywords that will be used to filter the response. If not supplied, all album types will be returned. Valid values are:
    • album
    • single
    • appears_on
    • compilation

Example: { album_type: ‘album,single’ }

  • country - Optional. An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one particular country. Note if you do not provide this field, you are likely to get duplicate results per album, one for each country in which the album is available!
  • limit - The number of album objects to return. Default: 20. Minimum: 1. Maximum: 50. For example: { limit: 2 }
  • offset - Optional. The index of the first album to return. Default: 0 (i.e., the first album). Use with limit to get the next set of albums.

Example:

  1. Spotify.getArtistAlbums('1vCWHaC5f2uS3yhpwWbIA6').then(function (data) {
  2. console.log(data);
  3. });