The Java SDK allows you to retrieve, create, and delete favorites. The following examples include code samples to help you get started with favorites.
deleteFavorites
allows you to delete the favorites tag for a file or folder.
Code Sample
public void deleteFavorites(OAuthToken token) throws IOException, CloudHttpException
{
CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
CloudClientContext context = new CloudClientContext(app, token);
CloudClient client = new CloudClient(context);
Metadata metadata = client.getMetadata("VZMOBILE", null, (SortTemplate)null, 1, 2, null);
List<FileMetadata> files = metadata.getFolder().getFile();
String uri = files.get(1).getUri();
// un-favorite first file in metadata response.
client.deleteTags(uri);
}
getFavorites
allows you to retrieve the files and folder for which the favorites tag has been set to true.
Code Sample
public Favorites getFavorites(OAuthToken token, String virtualfolder) throws IOException, CloudHttpException
{
CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
CloudClientContext context = new CloudClientContext(app, token);
CloudClient client = new CloudClient(context);
// retrieve all favorited image files.
return client.getFavorites(virtualfolder, FavoriteType.file, FavoriteFileType.image);
}
setFavorites
allows you to set the favorites tag for a file or folder to true.
Code Sample
public void favoriteFile(OAuthToken token) throws IOException, CloudHttpException
{
CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
CloudClientContext context = new CloudClientContext(app, token);
CloudClient client = new CloudClient(context);
Metadata metadata = client.getMetadata("VZMOBILE", null, (SortTemplate)null, 1, 2, null);
List<FileMetadata> files = metadata.getFolder().getFile();
List<String> uris = new ArrayList<>();
uris.add(files.get(0).getUri());
uris.add(files.get(1).getUri());
// tag 2 files as favorites.
client.setFavorites(uris);
}
Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.