Search in sources :

Example 1 with FlickrException

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);
    }
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) FlickrException(com.flickr4java.flickr.FlickrException) Auth(com.flickr4java.flickr.auth.Auth) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)

Example 2 with FlickrException

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);
    }
}
Also used : AuthInterface(com.flickr4java.flickr.auth.AuthInterface) FlickrException(com.flickr4java.flickr.FlickrException) Token(org.scribe.model.Token) IOException(java.io.IOException) Verifier(org.scribe.model.Verifier)

Example 3 with FlickrException

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);
    }
}
Also used : AuthInterface(com.flickr4java.flickr.auth.AuthInterface) FlickrException(com.flickr4java.flickr.FlickrException) Auth(com.flickr4java.flickr.auth.Auth) Token(org.scribe.model.Token) IOException(java.io.IOException) Verifier(org.scribe.model.Verifier)

Example 4 with FlickrException

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);
    }
}
Also used : TokenSecretAuthData(org.dataportabilityproject.shared.auth.TokenSecretAuthData) FlickrException(com.flickr4java.flickr.FlickrException) Auth(com.flickr4java.flickr.auth.Auth) Token(org.scribe.model.Token) IOException(java.io.IOException)

Example 5 with FlickrException

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);
}
Also used : IntPaginationToken(org.dataportabilityproject.spi.transfer.types.IntPaginationToken) PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) FlickrException(com.flickr4java.flickr.FlickrException) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) PhotoAlbum(org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Aggregations

FlickrException (com.flickr4java.flickr.FlickrException)12 IOException (java.io.IOException)7 Auth (com.flickr4java.flickr.auth.Auth)6 Photoset (com.flickr4java.flickr.photosets.Photoset)6 ArrayList (java.util.ArrayList)5 Photosets (com.flickr4java.flickr.photosets.Photosets)4 ImmutableList (com.google.common.collect.ImmutableList)4 AuthInterface (com.flickr4java.flickr.auth.AuthInterface)3 Photo (com.flickr4java.flickr.photos.Photo)3 PhotoList (com.flickr4java.flickr.photos.PhotoList)3 List (java.util.List)3 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)3 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)3 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)3 PhotoAlbum (org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum)3 Token (org.scribe.model.Token)3 Flickr (com.flickr4java.flickr.Flickr)2 REST (com.flickr4java.flickr.REST)2 RequestContext (com.flickr4java.flickr.RequestContext)2 PhotosInterface (com.flickr4java.flickr.photos.PhotosInterface)2