@Before public void setUp() { FacebookPhotosInterface photosInterface = mock(FacebookPhotosInterface.class); // Set up example album Album album = new Album(); album.setId(ALBUM_ID); album.setName(ALBUM_NAME); album.setDescription(ALBUM_DESCRIPTION); ArrayList<Album> albums = new ArrayList<>(); albums.add(album); @SuppressWarnings("unchecked") Connection<Album> albumConnection = mock(Connection.class); when(photosInterface.getAlbums(Mockito.any())).thenReturn(albumConnection); when(albumConnection.getData()).thenReturn(albums); // Set up example photo Photo photo = new Photo(); photo.setId(PHOTO_ID); Photo.Image image = new Photo.Image(); image.setSource(PHOTO_SOURCE); photo.addImage(image); photo.setName(PHOTO_NAME); ArrayList<Photo> photos = new ArrayList<>(); photos.add(photo); @SuppressWarnings("unchecked") Connection<Photo> photoConnection = mock(Connection.class); when(photosInterface.getPhotos(ALBUM_ID, Optional.empty())).thenReturn(photoConnection); when(photoConnection.getData()).thenReturn(photos); facebookPhotosExporter = new FacebookPhotosExporter(new AppCredentials("key", "secret"), photosInterface); }
Connection<Photo> photoConnection = getOrCreatePhotosInterface(authData).getPhotos(albumId, paginationToken); List<Photo> photos = photoConnection.getData(); for (Photo photo : photos) { Preconditions.checkNotNull(photo.getImages().get(0).getSource());
private ExportResult<PhotosContainerResource> exportAlbums( TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) { Optional<String> paginationToken = stripTokenPrefix(paginationData, ALBUM_TOKEN_PREFIX); ArrayList<PhotoAlbum> exportAlbums = new ArrayList<>(); // Get albums Connection<Album> connection = getOrCreatePhotosInterface(authData).getAlbums(paginationToken); PaginationData nextPageData = null; String token = connection.getAfterCursor(); if (!Strings.isNullOrEmpty(token)) { nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + token); } ContinuationData continuationData = new ContinuationData(nextPageData); List<Album> albums = connection.getData(); for (Album album : albums) { exportAlbums.add(new PhotoAlbum(album.getId(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getId())); } return new ExportResult<>( ExportResult.ResultType.CONTINUE, new PhotosContainerResource(exportAlbums, null), continuationData); }
@Override public List<PageMessageTag> getMessageTags() throws FacebookException { return facebookClient.fetchConnection(PAGE_MESSAGE_TAGS_PATH, PageMessageTag.class).getData(); } }
/** * @see java.util.Iterator#next() */ @Override public List<T> next() { // Special case: initial page will always have data, return it // immediately. if (initialPage) { initialPage = false; return connection.getData(); } if (!connection.hasNext()) { throw new NoSuchElementException("There are no more pages in the connection."); } connection = connection.fetchNextPage(); return connection.getData(); }
/** * Does this connection have a next page of data? * * @return {@code true} if there is a next page of data for this connection, {@code false} otherwise. */ public boolean hasNext() { return !isBlank(getNextPageUrl()) && !getData().isEmpty() && !isSameCursor(); }
Parameter.with("q", event), Parameter.with("type", "event"),Parameter.with("limit", 100)); System.out.println("Searching FB events for " + event); events= publicSearch.getData(); break;
Parameter.with("q", merchant), Parameter.with("type", "page"),Parameter.with("limit", 100)); System.out.println("Searching FB Pages for " + merchant); groups= publicSearch.getData(); break;