How can I create a new playlist in Spotify? I already have the access token from the user and the tracks objects stored locally, I'm trying by sending the request to the API but it asks for a user id which I don't have and don't know how to get. I find the spotify documentation a bit confusing.
This is how I search tracks
searchTracks(searchTerm:string,token:string) {
let url = this.tracksUrl + searchTerm;
let headers = new Headers();
headers.append('Authorization' , 'Bearer ' + token);
return this.http.get(url, {headers : headers}).map((res: Response) => res.json());
}
And this is how I get the token
ngOnInit() {//usar sessionStorage, dura solo hasta que cerras la ventana
this.token = sessionStorage.getItem('myToken');//null when not loaded
console.log("1st log:" + this.token);
if(this.token == null){
let possibleToken:string = window.location.href;//usar provider angular
let position:number = possibleToken.indexOf('access_token=')+13;//13 is the length of 'acces_token='
let lastPos:number = possibleToken.indexOf('&token_type');
if(lastPos !== -1){//if we have token
this.token = possibleToken.slice(position,lastPos);
console.log("2nd log" + this.token);
sessionStorage.setItem('myToken', this.token);
}
}
}
Aucun commentaire:
Enregistrer un commentaire