use of com.flickr4java.flickr.FlickrException in project data-transfer-project by google.
the class FlickrPhotosExporter method export.
@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, AuthData authData, ExportInformation exportInformation) {
Auth auth;
try {
auth = FlickrUtils.getAuth(authData, flickr);
} catch (FlickrException e) {
return new ExportResult<>(ResultType.ERROR, "Error authorizing user: " + e.getErrorMessage());
}
RequestContext.getRequestContext().setAuth(auth);
PaginationData paginationData = exportInformation.getPaginationData();
IdOnlyContainerResource resource = (IdOnlyContainerResource) exportInformation.getContainerResource();
if (resource != null) {
return getPhotos(resource, paginationData);
} else {
return getAlbums(paginationData, auth);
}
}
use of com.flickr4java.flickr.FlickrException in project data-transfer-project by google.
the class FlickrAuth method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, UUID jobId, AuthData initialAuthData, @Nullable String extra) throws IOException {
Preconditions.checkArgument(Strings.isNullOrEmpty(extra), "Extra data not expected");
Preconditions.checkNotNull(initialAuthData, "Earlier auth data not expected for Google flow");
AuthInterface authInterface = flickr.getAuthInterface();
Token token = fromAuthData(initialAuthData);
Token requestToken = authInterface.getAccessToken(token, new Verifier(authCode));
try {
authInterface.checkToken(requestToken);
return TokenSecretAuthData.create(requestToken.getToken(), requestToken.getSecret());
} catch (FlickrException e) {
throw new IOException("Problem verifying auth token", e);
}
}
use of com.flickr4java.flickr.FlickrException in project data-transfer-project by google.
the class FlickrAuth method generateAuthData.
@Override
public AuthData generateAuthData(IOInterface ioInterface) throws IOException {
AuthInterface authInterface = flickr.getAuthInterface();
Token token = authInterface.getRequestToken();
String url = authInterface.getAuthorizationUrl(token, Permission.WRITE);
String tokenKey = ioInterface.ask("Please enter the code from this authUrl: " + url);
Token requestToken = authInterface.getAccessToken(token, new Verifier(tokenKey));
try {
Auth auth = authInterface.checkToken(requestToken);
return toAuthData(requestToken);
} catch (FlickrException e) {
throw new IOException("Problem verifying auth token", e);
}
}
use of com.flickr4java.flickr.FlickrException in project data-transfer-project by google.
the class FlickrAuth method getAuth.
public Auth getAuth(AuthData authData) throws IOException {
checkArgument(authData instanceof TokenSecretAuthData, "authData expected to be TokenSecretAuthData not %s", authData.getClass().getCanonicalName());
Token requestToken = fromAuthData(authData);
try {
Auth auth = flickr.getAuthInterface().checkToken(requestToken);
return auth;
} catch (FlickrException e) {
throw new IOException("Problem verifying auth token", e);
}
}
use of com.flickr4java.flickr.FlickrException in project data-transfer-project by google.
the class FlickrPhotosExporter method getAlbums.
private ExportResult<PhotosContainerResource> getAlbums(PaginationData paginationData, Auth auth) {
ImmutableList.Builder<PhotoAlbum> albumBuilder = ImmutableList.builder();
List<IdOnlyContainerResource> subResources = new ArrayList<>();
int page = paginationData == null ? 1 : ((IntPaginationToken) paginationData).getStart();
Photosets photoSetList;
try {
photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
} catch (FlickrException e) {
return new ExportResult<>(ResultType.ERROR, "Error exporting Flickr album: " + e.getErrorMessage());
}
for (Photoset photoSet : photoSetList.getPhotosets()) {
// Saving data to the album allows the target service to recreate the album structure
albumBuilder.add(new PhotoAlbum(photoSet.getId(), photoSet.getTitle(), photoSet.getDescription()));
// Adding subresources tells the framework to recall export to get all the photos
subResources.add(new IdOnlyContainerResource(photoSet.getId()));
}
PaginationData newPage = null;
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
if (hasMore)
newPage = new IntPaginationToken(page + 1);
PhotosContainerResource photosContainerResource = new PhotosContainerResource(albumBuilder.build(), null);
ContinuationData continuationData = new ContinuationData(newPage);
subResources.forEach(resource -> continuationData.addContainerResource(resource));
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (newPage == null) {
resultType = ResultType.END;
}
return new ExportResult<>(resultType, photosContainerResource, continuationData);
}
Aggregations