Bucky00 / bwa-u3-jammming-prj

Codecademy Jammming Project
0 stars 0 forks source link

Not able to connect to Spotify #2

Open carodelafuente opened 6 years ago

carodelafuente commented 6 years ago

When I click search, I am not able to connect to the Spotify API, the browser directs me to a page that says: Missing required parameter: client_id. You seem to be missing your client_id in your params for your access URL.

You could refactor some of your code in your Spotify.js file, you don't necessarily need a function for getHashParams() or generateRandomString(). Outside your Spotify object, all you really need is to declare client_id, redirect_uri, and accessToken, then inside your getAccessToken function, you create a conditional that only checks for (accessTokenMatch && expiresInMatch), then in that else statement, you set the redirect, something like this:

      const access_url = `https://accounts.spotify.com/authorize?client_id=${client_id}&response_type=token&scope=playlist-modify-public&redirect_uri=${redirect_uri}`;
      window.location = access_url;

Might be some other minor details you'd have to refactor as well but that's the general gist of what you could do for the redirect functionality.

Bucky00 commented 6 years ago

Per Spotify recommendations, I removed my client id number from the Spotify.js file when posting to GitHub. let client_id = ''; //client_id removed from GitHub version I thought reviewers put their own client id in the code to make it run. I've updated my Spotify.js with my client id. It will work as stated.

The getHashParams()and generateRandomString()functions are from Spotify's example on their site. I implemented the state functionality, which they recommended. This adds a random state value to the Spotify request. The random state is also saved to the users cookie. When the reply is returned from Spotify they include the state value, which I check against the value saved to the users cookie. If state is there and equal to what was sent and accessTokenMatch and expiresInMatch are true than access token is set.

Do you want the extra security removed before reviewing?