Search in sources :

Example 1 with MediaFeedData

use of org.datatransferproject.transfer.instagram.photos.model.MediaFeedData in project data-transfer-project by google.

the class InstagramPhotoExporter method exportPhotos.

private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
    Preconditions.checkNotNull(authData);
    MediaResponse response;
    try {
        response = makeRequest(MEDIA_URL, MediaResponse.class, authData);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
    List<PhotoModel> photos = new ArrayList<>();
    // TODO: check out paging.
    for (MediaFeedData photo : response.getData()) {
        // TODO json mapping is broken.
        String photoId = photo.getId();
        String url = photo.getImages().getStandardResolution().getUrl();
        String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null;
        photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, photoId, FAKE_ALBUM_ID, false));
    }
    List<PhotoAlbum> albums = new ArrayList<>();
    if (!photos.isEmpty() && !pageData.isPresent()) {
        albums.add(new PhotoAlbum(FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram"));
    }
    return new ExportResult<>(ResultType.END, new PhotosContainerResource(albums, photos));
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) MediaResponse(org.datatransferproject.transfer.instagram.photos.model.MediaResponse) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) MediaFeedData(org.datatransferproject.transfer.instagram.photos.model.MediaFeedData) IOException(java.io.IOException) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 MediaFeedData (org.datatransferproject.transfer.instagram.photos.model.MediaFeedData)1 MediaResponse (org.datatransferproject.transfer.instagram.photos.model.MediaResponse)1 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)1 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)1 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)1