Skip to content

Instantly share code, notes, and snippets.

@JMPerez
Created October 19, 2015 19:19
Show Gist options
  • Save JMPerez/6aa3b0b3dcf9253235ad to your computer and use it in GitHub Desktop.
Save JMPerez/6aa3b0b3dcf9253235ad to your computer and use it in GitHub Desktop.
Fix for Yami's project
// in portfolio/public/scripts.js
// [...]
/**
* Returns an object with the query parameters passed in the
* hash of the URL
*/
function getHashParams() {
var hashParams = {};
var e, r = /([^&;=]+)=?([^&;]*)/g,
q = window.location.hash.substring(1);
while ( e = r.exec(q)) {
hashParams[e[1]] = decodeURIComponent(e[2]);
}
return hashParams;
}
$(document).ready(function($) {
$('#s').on('submit', function() {
searchArtists($('#originalartist').val());
return false;
});
// read the parameters
var params = getHashParams();
// if "access_token" is there, it probably means that we have come back from the
// Spotify authentication page, and we now have an access token
if (params.access_token) {
// yuhu!!!
// make sure the Spotify Web API JS wrapper has an access token that it can use
// to fetch the current user's info
s.setAccessToken(params.access_token);
// and now, let's call getMe(). Here we are using a Promise, but we could have
// also used a callback function
s.getMe().then(function(data) {
// and here it goes the user's data!!!
console.log(data);
});
}
});
// [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment