Skip to content

Instantly share code, notes, and snippets.

@achimoraites
Created October 24, 2018 11:30
Show Gist options
  • Save achimoraites/d32683158afc80ee8a055bdd43319e8b to your computer and use it in GitHub Desktop.
Save achimoraites/d32683158afc80ee8a055bdd43319e8b to your computer and use it in GitHub Desktop.
Using spotify api without headaches
search() {
console.log('this.state', this.state);
const BASE_URL = 'https://api.spotify.com/v1/search?';
const FETCH_URL = `${BASE_URL}q=${this.state.query}&type=artist&limit=1`;
// get your access token : https://developer.spotify.com/console/get-search-item/
// click get token button , copy paste the token below and you are good to go
var accessToken = 'YOUR_TOKEN';
var myOptions = {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + accessToken
},
mode: 'cors',
cache: 'default'
};
fetch(FETCH_URL, myOptions )
.then(response => response.json())
.then(json => {
const artist = json.artists.items[0];
this.setState({artist})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment