wlu314 / Spotify-Stats-Tool

Spotify Wrapped Stats
MIT License
1 stars 0 forks source link

Login Page: Spotify API #3

Open wlu314 opened 7 months ago

wlu314 commented 7 months ago

As the user first opens the app, if the user doesn't have an account, they will create a new account and login into Spotify. The entered information should be stored in our database. If user already has an account, checked after the splash screen, then user will be prompted to the home page.

Serenata27 commented 7 months ago

Imported Spotify sdk

wlu314 commented 7 months ago

This code includes the SpotifyAPI package and the ConnectSpotifyPage.java

Flow of Method Calls

  1. User initiates login: The user clicks on the login button (R.id.spotify_login_btn) in the ConnectSpotifyPage activity, which triggers spotifyHandler.initiateLogin().

  2. Spotify login and authorization: initiateLogin() builds and sends an authentication request to Spotify. If the user authorizes your application, Spotify redirects the user back to your application with an intent that contains the authorization code or access token

  3. Handling the redirect: The Android system calls onNewIntent(Intent intent) in the ConnectSpotifyPage activity, providing the intent that contains the URI with the authentication response. onNewIntent then calls spotifyHandler.handleIntent(intent).

  4. Processing the authentication response: handleIntent extracts the data from the URI and processes the authentication response. If the authentication is successful and an authorization code is received, it calls requestAccessToken(authorizationCode) to exchange the authorization code for an access token. If the response contains an access token directly, it can notify the listener immediately.

  5. Exchanging the authorization code for an access token: The requestAccessToken method sends a request to Spotify's /api/token endpoint to exchange the authorization code for an access token and, if successful, notifies the listener by calling onTokenReceived(accessToken).

  6. Fetching user information: Once the access token is received, onTokenReceived is called, which triggers fetchUserInformation(accessToken) to retrieve the user's Spotify profile information.

  7. Navigation: Finally, after the user's information is fetched, onTokenReceived navigates the user to another activity (e.g., Statistics).

Potential Considerations