Java Code Examples for com.spotify.sdk.android.authentication.AuthenticationClient#getResponse()

The following examples show how to use com.spotify.sdk.android.authentication.AuthenticationClient#getResponse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpotifyManagerImpl.java    From mirror with Apache License 2.0 6 votes vote down vote up
@Override
public void onAuthenticationResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != SpotifyManager.REQUEST_CODE) {
        return;
    }

    AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, data);
    switch (response.getType()) {
        case TOKEN:
            onAuthenticationComplete(response.getAccessToken());
            break;
        case ERROR:
            Timber.e("Auth error: %s", response.getError());
            break;
        default:
            Timber.e("Auth result: %s", response.getType());
    }
}
 
Example 2
Source File: LoginActivity.java    From spotify-web-api-android with MIT License 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    // Check if result comes from the correct activity
    if (requestCode == REQUEST_CODE) {
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
        switch (response.getType()) {
            // Response was successful and contains auth token
            case TOKEN:
                logMessage("Got token: " + response.getAccessToken());
                CredentialsHandler.setToken(this, response.getAccessToken(), response.getExpiresIn(), TimeUnit.SECONDS);
                startMainActivity(response.getAccessToken());
                break;

            // Auth flow returned an error
            case ERROR:
                logError("Auth error: " + response.getError());
                break;

            // Most likely auth flow was cancelled
            default:
                logError("Auth result: " + response.getType());
        }
    }
}
 
Example 3
Source File: CPlaylistActivity.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE) {
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, data);

        switch (response.getType()) {
            // Response was successful and contains auth token
            case TOKEN:
                Log.e(TAG, "onActivityResult: "+response.getAccessToken() );
                Log.e(TAG,"Expires in: "+response.getExpiresIn());

                alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(View.GONE);
                alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);

                Toast.makeText(this, "Success: connected to Spotify app!", Toast.LENGTH_SHORT).show();

                accessToken = response.getAccessToken();

                break;

            case ERROR:
                Log.e(TAG, "onActivityResult: "+response.getError() );
                alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(View.VISIBLE);
                Toast.makeText(this, "Couldn't connect to Spotify!", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
 
Example 4
Source File: SpotifyLoginActivity.java    From android-spotify-demo with MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, final int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == REQUEST_CODE)
    {
        final AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, data);

        switch (response.getType()) {
            // Response was successful and contains auth token
            case TOKEN:

                Intent intent = new Intent(SpotifyLoginActivity.this,
                        MainActivity.class);

                intent.putExtra(AUTH_TOKEN, response.getAccessToken());

                startActivity(intent);

                destroy();

                break;

            // Auth flow returned an error
            case ERROR:
                Log.e(TAG,"Auth error: " + response.getError());
                break;

            // Most likely auth flow was cancelled
            default:
                Log.d(TAG,"Auth result: " + response.getType());
        }
    }
}