use of com.google.gdata.data.photos.UserFeed in project data-transfer-project by google.
the class GooglePhotosExporter method exportAlbums.
private ExportResult<PhotosContainerResource> exportAlbums(TokensAndUrlAuthData authData, Optional<PaginationData> paginationData) {
try {
int startItem = 1;
if (paginationData.isPresent()) {
String token = ((StringPaginationToken) paginationData.get()).getToken();
Preconditions.checkArgument(token.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + token);
startItem = Integer.parseInt(token.substring(ALBUM_TOKEN_PREFIX.length()));
}
URL albumUrl = new URL(String.format(URL_ALBUM_FEED_FORMAT, startItem, MAX_RESULTS));
UserFeed albumFeed = getOrCreatePhotosService(authData).getFeed(albumUrl, UserFeed.class);
PaginationData nextPageData = null;
if (albumFeed.getAlbumEntries().size() == MAX_RESULTS) {
int nextPageStart = startItem + MAX_RESULTS;
nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + nextPageStart);
}
ContinuationData continuationData = new ContinuationData(nextPageData);
List<PhotoAlbum> albums = new ArrayList<>(albumFeed.getAlbumEntries().size());
for (GphotoEntry googleAlbum : albumFeed.getAlbumEntries()) {
// Add album info to list so album can be recreated later
albums.add(new PhotoAlbum(googleAlbum.getGphotoId(), googleAlbum.getTitle().getPlainText(), googleAlbum.getDescription().getPlainText()));
// Add album id to continuation data
continuationData.addContainerResource(new IdOnlyContainerResource(googleAlbum.getGphotoId()));
}
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null || continuationData.getContainerResources().isEmpty()) {
resultType = ResultType.END;
}
PhotosContainerResource containerResource = new PhotosContainerResource(albums, null);
return new ExportResult<>(resultType, containerResource, continuationData);
} catch (ServiceException | IOException e) {
return new ExportResult<>(ResultType.ERROR, e.getMessage());
}
}
use of com.google.gdata.data.photos.UserFeed in project data-transfer-project by google.
the class GooglePhotosService method exportAlbums.
private PhotosModelWrapper exportAlbums(Optional<PaginationInformation> pageInfo) throws IOException {
URL albumUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default?kind=album");
UserFeed albumFeed;
try {
albumFeed = service.getFeed(albumUrl, UserFeed.class);
} catch (ServiceException e) {
throw new IOException("Problem making request to: " + albumUrl, e);
}
List<PhotoAlbum> albums = new ArrayList<>(albumFeed.getEntries().size());
List<Resource> resources = new ArrayList<>(albumFeed.getEntries().size());
for (GphotoEntry myAlbum : albumFeed.getEntries()) {
// Adding sub-resources tells the framework to re-call
// export to get all the photos.
resources.add(new IdOnlyResource(myAlbum.getGphotoId()));
// Saving data to the album allows the target service
// to recreate the album structure.
albums.add(new PhotoAlbum(myAlbum.getGphotoId(), myAlbum.getTitle().getPlainText(), myAlbum.getDescription().getPlainText()));
}
return new PhotosModelWrapper(albums, null, new ContinuationInformation(resources, null));
}
Aggregations