Search in sources :

Example 1 with ClientCredentials

use of se.michaelthelin.spotify.model_objects.credentials.ClientCredentials in project spotify-web-api-java by spotify-web-api-java.

the class ClientCredentialsExample method clientCredentials_Async.

public static void clientCredentials_Async() {
    try {
        final CompletableFuture<ClientCredentials> clientCredentialsFuture = clientCredentialsRequest.executeAsync();
        // Thread free to do other tasks...
        // Example Only. Never block in production code.
        final ClientCredentials clientCredentials = clientCredentialsFuture.join();
        // Set access token for further "spotifyApi" object usage
        spotifyApi.setAccessToken(clientCredentials.getAccessToken());
        System.out.println("Expires in: " + clientCredentials.getExpiresIn());
    } catch (CompletionException e) {
        System.out.println("Error: " + e.getCause().getMessage());
    } catch (CancellationException e) {
        System.out.println("Async operation cancelled.");
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) ClientCredentials(se.michaelthelin.spotify.model_objects.credentials.ClientCredentials)

Example 2 with ClientCredentials

use of se.michaelthelin.spotify.model_objects.credentials.ClientCredentials in project spotify-web-api-java by spotify-web-api-java.

the class ClientCredentialsExample method clientCredentials_Sync.

public static void clientCredentials_Sync() {
    try {
        final ClientCredentials clientCredentials = clientCredentialsRequest.execute();
        // Set access token for further "spotifyApi" object usage
        spotifyApi.setAccessToken(clientCredentials.getAccessToken());
        System.out.println("Expires in: " + clientCredentials.getExpiresIn());
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        System.out.println("Error: " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) ClientCredentials(se.michaelthelin.spotify.model_objects.credentials.ClientCredentials) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Aggregations

ClientCredentials (se.michaelthelin.spotify.model_objects.credentials.ClientCredentials)2 IOException (java.io.IOException)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionException (java.util.concurrent.CompletionException)1 ParseException (org.apache.hc.core5.http.ParseException)1 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)1