public Connection<Album> getAlbums(Optional<String> paginationToken) { ArrayList<Parameter> parameters = new ArrayList<>(); parameters.add(Parameter.with("fields", "description,name")); paginationToken.ifPresent(token -> parameters.add(Parameter.with("after", token))); return client.fetchConnection("me/albums", Album.class, parameters.toArray(new Parameter[0])); }
RestFbFacebookPhotos(TokensAndUrlAuthData authData, AppCredentials appCredentials) { client = new DefaultFacebookClient( authData.getAccessToken(), appCredentials.getSecret(), Version.VERSION_3_0); }
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); }
@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); }
@Override public void removeGreeting() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.greeting)); }
Connection<Photo> photoConnection = getOrCreatePhotosInterface(authData).getPhotos(albumId, paginationToken); List<Photo> photos = photoConnection.getData(); for (Photo photo : photos) { Preconditions.checkNotNull(photo.getImages().get(0).getSource()); exportPhotos.add( new PhotoModel( String.format("%s.jpg", photo.getId()), photo.getImages().get(0).getSource(), photo.getName(), "image/jpg", photo.getId(), albumId, false)); String token = photoConnection.getAfterCursor(); if (Strings.isNullOrEmpty(token)) { return new ExportResult<>(
private FacebookClient.AccessToken getFacebookUserToken(String code, String redirectUrl) throws IOException { String appId = "YOUR_APP_ID"; String secretKey = "YOUR_SECRET_KEY"; WebRequestor wr = new DefaultWebRequestor(); WebRequestor.Response accessTokenResponse = wr.executeGet( "https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&redirect_uri=" + redirectUrl + "&client_secret=" + secretKey + "&code=" + code); return DefaultFacebookClient.AccessToken.fromQueryString(accessTokenResponse.getBody()); }
/** * Creates a Facebook Graph API client with the given {@code apiVersion}. * * @param apiVersion * Version of the api endpoint */ public DefaultFacebookClient(Version apiVersion) { this(null, null, new DefaultWebRequestor(), new DefaultJsonMapper(), apiVersion); }
@Override public String getLogoutUrl(String next) { String parameterString; if (next != null) { Parameter p = Parameter.with("next", next); parameterString = toParameterString(false, p); } else { parameterString = toParameterString(false); } final String fullEndPoint = createEndpointForApiCall("logout.php", false); return fullEndPoint + "?" + parameterString; }
@Override public List<PageMessageTag> getMessageTags() throws FacebookException { return facebookClient.fetchConnection(PAGE_MESSAGE_TAGS_PATH, PageMessageTag.class).getData(); } }
/** * Returns the base endpoint URL for the Graph API's video upload functionality. * * @return The base endpoint URL for the Graph API's video upload functionality. * @since 1.6.5 */ protected String getFacebookGraphVideoEndpointUrl() { if (apiVersion.isUrlElementRequired()) { return getFacebookEndpointUrls().getGraphVideoEndpoint() + '/' + apiVersion.getUrlElement(); } else { return getFacebookEndpointUrls().getGraphVideoEndpoint(); } }
/** * Returns the base endpoint URL for the Graph API. * * @return The base endpoint URL for the Graph API. */ protected String getFacebookGraphEndpointUrl() { if (apiVersion.isUrlElementRequired()) { return getFacebookEndpointUrls().getGraphEndpoint() + '/' + apiVersion.getUrlElement(); } else { return getFacebookEndpointUrls().getGraphEndpoint(); } }
FacebookClient.AccessToken token = getFacebookUserToken(code, redirectUrl); String accessToken = token.getAccessToken(); Date expires = token.getExpires();
@JsonMapper.JsonMappingCompleted void convertData(JsonMapper mapper) { if (data != null) { metaData = mapper.toJavaObject(data, MetaData.class); } }
/** * @see com.restfb.LegacyFacebookClient#execute(String, * String, Class, com.restfb.Parameter[]) */ @Override public <T> T execute(String method, String sessionKey, Class<T> resultType, Parameter... parameters) { return jsonMapper.toJavaObject(makeRequest(method, sessionKey, parameters), resultType); }
@Override public void removeGetStartedButton() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions), Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.new_thread)); }
/** * Creates a Facebook Graph API client with the given {@code accessToken}. * * @param accessToken * A Facebook OAuth access token. * @param apiVersion * Version of the api endpoint * @since 1.6.14 */ public DefaultFacebookClient(String accessToken, Version apiVersion) { this(accessToken, null, new DefaultWebRequestor(), new DefaultJsonMapper(), apiVersion); }
public Connection<Photo> getPhotos(String albumId, Optional<String> paginationToken) { ArrayList<Parameter> parameters = new ArrayList<>(); parameters.add(Parameter.with("fields", "name,images")); paginationToken.ifPresent(token -> parameters.add(Parameter.with("after", token))); return client.fetchConnection( String.format("%s/photos", albumId), Photo.class, parameters.toArray(new Parameter[0])); } }
@Override public void removePersistentMenu() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions), Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.existing_thread)); }
@Override public void removeAccountLinkingUrl() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.account_linking)); }