Created
October 19, 2015 19:19
-
-
Save JMPerez/6aa3b0b3dcf9253235ad to your computer and use it in GitHub Desktop.
Fix for Yami's project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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