I\'m doing this course in udemy about building 12 different angular 2 apps, and one of them works with Spotify Web API and I\'m adding more features to it;
I\'ve learn h
You may find it helpful if other answers wouldn't work...
import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class SearchService {
private searchUrl: string;
constructor (private _http: Http) {
}
searchMusic(str:string, type='artist'){
let headers = new Headers();
let authToken = 'Your OAuth Token Goes Here';
headers.append('Authorization', 'Bearer '+authToken);
this.searchUrl = 'https://api.spotify.com/v1/search?q='+str+'&offset=0&limit=20&type='+type+'&market=US';
return this._http.get(this.searchUrl, { headers })
.map(res => res.json());
}
}
You can also generate OAuth Token from below link:
https://developer.spotify.com/web-api/console/get-search-item/