本文整理汇总了Java中com.wrapper.spotify.methods.PlaylistRequest类的典型用法代码示例。如果您正苦于以下问题:Java PlaylistRequest类的具体用法?Java PlaylistRequest怎么用?Java PlaylistRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlaylistRequest类属于com.wrapper.spotify.methods包,在下文中一共展示了PlaylistRequest类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPlaylistById
import com.wrapper.spotify.methods.PlaylistRequest; //导入依赖的package包/类
private static Playlist getPlaylistById(String spotifyId, String playlistId, Api api) {
final PlaylistRequest request = api.getPlaylist(spotifyId, playlistId).build();
try {
return request.get();
} catch (Exception e) {
e.printStackTrace();
throw new WrapperException();
}
}
示例2: main
import com.wrapper.spotify.methods.PlaylistRequest; //导入依赖的package包/类
public static void main(String[] args) {
try {
while(true) {
//Get an authenticated client
spotifyApi = spotifyClient.getSpotifyApi();
spotifyApi.getPlaylistTracks(userId, playlistId);
PlaylistRequest request = spotifyApi.getPlaylist(userId, playlistId).build();
try {
Playlist playlist = request.get();
List<ComparablePlaylistTrack> newTracks = getNewPlaylistTracks(playlist);
for(PlaylistTrack t : newTracks) {
postToSlack(playlist, t);
redisClient.addNewTrack(t);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
//Repeat playlist check every minute
Thread.sleep(60 * 1000);
}
} catch (InterruptedException ie) {
System.out.println("Thread interrupted!!");
}
}
示例3: process
import com.wrapper.spotify.methods.PlaylistRequest; //导入依赖的package包/类
public void process(String url) throws UnsupportedEncodingException {
//Decodeamos y encodeamos los nombres de usuario
String user = URLEncoder.encode(URLDecoder.decode(getUser(url), "UTF-8"), "UTF-8");
String idP = getIdPlayList(url);
System.out.println("Usuario: " + user + " - ID PlayList: " + idP);
textui.printText("Usuario: " + user + " - ID PlayList: " + idP);
// Create an API instance. The default instance connects to https://api.spotify.com/.
api = Api.builder()
.clientId(clientId)
.clientSecret(clientSecret)
.redirectURI("https://www.spotify.com/es/")
.build();
final ClientCredentialsGrantRequest request = api.clientCredentialsGrant().build();
/* Use the request object to make the request, either asynchronously (getAsync) or synchronously (get) */
final SettableFuture<ClientCredentials> responseFuture = request.getAsync();
/* Add callbacks to handle success and failure */
Futures.addCallback(responseFuture, new FutureCallback<ClientCredentials>() {
@Override
public void onSuccess(ClientCredentials clientCredentials) {
/* Set access token on the Api object so that it's used going forward */
api.setAccessToken(clientCredentials.getAccessToken());
textui.printText("Procediendo a analizar la playList...");
//Sacamos el numero de tracks que tiene la playlist
final PlaylistRequest infoPlayListRequest = api.getPlaylist(user, idP).build();
try {
final Playlist playlist = infoPlayListRequest.get();
numTracks = playlist.getTracks().getTotal();
System.out.println("Num Tracks PlayList: " + numTracks);
textui.printText("Num Tracks PlayList: " + numTracks);
//Sacamos las canciones pasando el offset y el limite
for (int i = 0; i <= numTracks - 1; i += 30) {
cargarCanciones(i, 30, user, idP,textui);
}
} catch (Exception e) {
System.out.println("Something went wrong!" + e.getMessage());
textui.printText("Something went wrong!" + e.getMessage());
}
}
@Override
public void onFailure(Throwable throwable) {
/* An error occurred while getting the access token. This is probably caused by the client id or
* client secret is invalid. */
}
});
}