Skip to content

Commit e446521

Browse files
committed
Examples
+- Example classes for every request + README for default data
1 parent d0fa4a6 commit e446521

79 files changed

Lines changed: 4239 additions & 179 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎examples/AuthorizationCodeGrant.java‎

Lines changed: 0 additions & 59 deletions
This file was deleted.

‎examples/ClientCredentialsFlow.java‎

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎examples/GetAuthenticatedUserInformation.java‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎examples/README.md‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Examples
2+
Here you can find example code snippets.
3+
4+
## Default Data
5+
The following (random) data should be used when modifying examples:
6+
7+
### Authorization
8+
- Client ID: `"zyuxhfo1c51b5hxjk09x2uhv5n0svgd6g"`
9+
- Client secret: `"zudknyqbh3wunbhcvg9uyvo7uwzeu6nne"`
10+
- Redirect URI: `new URIBuilder().setScheme("https").setHost("example.com").setPath("spotify-redirect").build()`
11+
- Refresh token: `"b0KuPuLw77Z0hQhCsK-GTHoEx_kethtn357V7iqwEpCTIsLgqbBC_vQBTGC6M5rINl0FrqHK-D3cbOsMOlfyVKuQPvpyGcLcxAoLOTpYXc28nVwB7iBq2oKj9G9lHkFOUKn"`
12+
- Access token: `"taHZ2SdB-bPA3FsK3D7ZN5npZS47cMy-IEySVEGttOhXmqaVAIo0ESvTCLjLBifhHOHOIuhFUKPW1WMDP7w6dj3MAZdWT8CLI2MkZaXbYLTeoDvXesf2eeiLYPBGdx8tIwQJKgV8XdnzH_DONk"`
13+
14+
### IDs
15+
- Artist: ["0LcJLqbBmaGUft1e9Mm8HV"](https://open.spotify.com/artist/0LcJLqbBmaGUft1e9Mm8HV?si=tUHw6JYdQwmE5QIla_7ZaQ)
16+
- Album: ["5zT1JLIj9E57p3e1rFm9Uq"](https://open.spotify.com/album/5zT1JLIj9E57p3e1rFm9Uq?si=PkAs2KWQTkm2b0vxg_qcRA)
17+
- Playlist: ["3AGOiaoRXMSjswCLtuNqv5"](https://open.spotify.com/user/abbaspotify/playlist/3AGOiaoRXMSjswCLtuNqv5?si=ru1yCc8QSueG7gHEC7E40w)
18+
- Track: ["01iyCAUm8EvOFqVWYJ3dVX"](https://open.spotify.com/track/01iyCAUm8EvOFqVWYJ3dVX?si=m0Fdh5ASScyfue6kQerIZg)
19+
- User: ["abbaspotify"](https://open.spotify.com/user/abbaspotify?si=xlmKbz6mQZ6fLfqwtOGozg)
20+
21+
### Required
22+
- Category ID: `"dinner"`
23+
- Country: `CountryCode.SE`
24+
- Ids: see appropriate IDs
25+
- Insert before: `0`
26+
- Model object type: first appropriate
27+
- Public: `false`
28+
- Q: `"Abba"`
29+
- Range start: `0`
30+
- State: `"track"` or `true`
31+
- Type: `"track"`
32+
- Volume percent: `100`
33+
34+
### Optional
35+
- After: see appropriate IDs or `new Date(1517087230)`
36+
- Album type: `"album"`
37+
- Before: `new Date(1453932420)`
38+
- Collaborative: `false`
39+
- Context URI: `"spotify:album:5zT1JLIj9E57p3e1rFm9Uq"`
40+
- Description: `"Amazing music."`
41+
- Device ID: `"5fbb3ba6aa454b5534c4ba43a8c7e8e45a63ad0e"`
42+
- Fields: `"description"`
43+
- Image data: see `image_data.txt`
44+
- Limit: `10`
45+
- Locale: `"sv_SE"`
46+
- Market: `CountryCode.SE`
47+
- Max popularity: `50`
48+
- Min popularity: `10`
49+
- Name: `"Abba"`
50+
- Offset: `0` or `new JsonParser().parse("[\"spotify:track:01iyCAUm8EvOFqVWYJ3dVX\"]").getAsJsonObject()`
51+
- Play: `false`
52+
- Position: `0`
53+
- Public: `false`
54+
- Range length: `0`
55+
- Scope: `"user-read-birthdate"`
56+
- Seed artists: `"0LcJLqbBmaGUft1e9Mm8HV"`
57+
- Seed genres: `"electro"`
58+
- Seed tracks: `"01iyCAUm8EvOFqVWYJ3dVX"`
59+
- Show dialog: true
60+
- Snapshot ID: `"JbtmHBDBAYu3/bt8BOXKjzKx3i0b6LCa/wVjyl6qQ2Yf6nFXkbmzuEa+ZI/U1yF+"`
61+
- State: `"x4xkmn9pu3j6ukrs8n"`
62+
- Target popularity: `20`
63+
- Time range: `"medium_term"`
64+
- Timestamp: `new Date(1414054800)`
65+
- Tracks: `new JsonParser().parse("[\"01iyCAUm8EvOFqVWYJ3dVX\"]").getAsJsonArray()`
66+
- URIs: `new JsonParser().parse("{\"position\": 0}").getAsJsonArray()`
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package authorization.authorization_code;
2+
3+
import com.wrapper.spotify.SpotifyApi;
4+
import com.wrapper.spotify.model_objects.credentials.AuthorizationCodeCredentials;
5+
import com.wrapper.spotify.requests.authorization.authorization_code.AuthorizationCodeRequest;
6+
import org.apache.http.client.utils.URIBuilder;
7+
8+
import java.net.URI;
9+
import java.net.URISyntaxException;
10+
import java.util.concurrent.Future;
11+
12+
public class AuthorizationCodeExample {
13+
private static final String clientId = "zyuxhfo1c51b5hxjk09x2uhv5n0svgd6g";
14+
private static final String clientSecret = "zudknyqbh3wunbhcvg9uyvo7uwzeu6nne";
15+
private static URI redirectUri = null;
16+
private static final String code = "";
17+
18+
static {
19+
try {
20+
redirectUri = new URIBuilder().setScheme("https").setHost("example.com").setPath("spotify-redirect").build();
21+
} catch (URISyntaxException e) {
22+
e.printStackTrace();
23+
}
24+
}
25+
26+
private static final SpotifyApi spotifyApi = new SpotifyApi.Builder()
27+
.setClientId(clientId)
28+
.setClientId(clientSecret)
29+
.setRedirectUri(redirectUri)
30+
.build();
31+
private static final AuthorizationCodeRequest authorizationCodeRequest = spotifyApi.authorizationCode(code)
32+
.build();
33+
34+
public static void authorizationCode_Sync() {
35+
try {
36+
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeRequest.execute();
37+
38+
// Set access and refresh token for further "spotifyApi" object usage
39+
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
40+
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());
41+
42+
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
43+
} catch (Exception e) {
44+
System.out.println("Something went wrong!\n" + e.getMessage());
45+
}
46+
}
47+
48+
public static void authorizationCode_Async() {
49+
try {
50+
final Future<AuthorizationCodeCredentials> authorizationCodeCredentialsFuture = authorizationCodeRequest.executeAsync();
51+
52+
// ...
53+
54+
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeCredentialsFuture.get();
55+
56+
// Set access and refresh token for further "spotifyApi" object usage
57+
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
58+
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());
59+
60+
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
61+
} catch (Exception e) {
62+
System.out.println("Something went wrong!\n" + e.getMessage());
63+
}
64+
}
65+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package authorization.authorization_code;
2+
3+
import com.wrapper.spotify.SpotifyApi;
4+
import com.wrapper.spotify.model_objects.credentials.AuthorizationCodeCredentials;
5+
import com.wrapper.spotify.requests.authorization.authorization_code.AuthorizationCodeRefreshRequest;
6+
import org.apache.http.client.utils.URIBuilder;
7+
8+
import java.net.URI;
9+
import java.net.URISyntaxException;
10+
import java.util.concurrent.Future;
11+
12+
public class AuthorizationCodeRefreshExample {
13+
private static final String clientId = "zyuxhfo1c51b5hxjk09x2uhv5n0svgd6g";
14+
private static final String clientSecret = "zudknyqbh3wunbhcvg9uyvo7uwzeu6nne";
15+
private static final String refreshToken = "b0KuPuLw77Z0hQhCsK-GTHoEx_kethtn357V7iqwEpCTIsLgqbBC_vQBTGC6M5rINl0FrqHK-D3cbOsMOlfyVKuQPvpyGcLcxAoLOTpYXc28nVwB7iBq2oKj9G9lHkFOUKn";
16+
17+
private static final SpotifyApi spotifyApi = new SpotifyApi.Builder()
18+
.setClientId(clientId)
19+
.setClientId(clientSecret)
20+
.setRefreshToken(refreshToken)
21+
.build();
22+
private static final AuthorizationCodeRefreshRequest authorizationCodeRefreshRequest = spotifyApi.authorizationCodeRefresh()
23+
.build();
24+
25+
public static void authorizationCodeRefresh_Sync() {
26+
try {
27+
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeRefreshRequest.execute();
28+
29+
// Set access and refresh token for further "spotifyApi" object usage
30+
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
31+
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());
32+
33+
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
34+
} catch (Exception e) {
35+
System.out.println("Something went wrong!\n" + e.getMessage());
36+
}
37+
}
38+
39+
public static void authorizationCodeRefresh_Async() {
40+
try {
41+
final Future<AuthorizationCodeCredentials> authorizationCodeCredentialsFuture = authorizationCodeRefreshRequest.executeAsync();
42+
43+
// ...
44+
45+
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeCredentialsFuture.get();
46+
47+
// Set access and refresh token for further "spotifyApi" object usage
48+
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
49+
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());
50+
51+
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
52+
} catch (Exception e) {
53+
System.out.println("Something went wrong!\n" + e.getMessage());
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)