/** * 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); }
/** * Creates a Facebook API client with the given <a * href="http://developers.facebook.com/docs/guides/upgrade#oauth">OAuth * access token</a>. * * @param accessToken An OAuth access token. * @throws NullPointerException If {@code accessToken} is {@code null}. * @throws IllegalArgumentException If {@code accessToken} is a blank string. * @since 1.5 */ public DefaultLegacyFacebookClient(String accessToken) { this(accessToken, new DefaultWebRequestor(), new DefaultJsonMapper()); }
/** * 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); }
/** * Creates a Facebook Graph API client with the given {@code accessToken}. * * @param accessToken A Facebook OAuth access token. */ public DefaultFacebookClient(String accessToken) { this(accessToken, new DefaultWebRequestor(), new DefaultJsonMapper()); }
/** * Creates a Facebook Graph API client with the given {@code accessToken}. * * @param accessToken * A Facebook OAuth access token. * @param appSecret * A Facebook application secret. * @param apiVersion * Version of the api endpoint * @since 1.6.14 */ public DefaultFacebookClient(String accessToken, String appSecret, Version apiVersion) { this(accessToken, appSecret, new DefaultWebRequestor(), new DefaultJsonMapper(), apiVersion); }
/** * Creates a Facebook API client with the given API key and secret key (Legacy * authentication). * * @param apiKey A Facebook API key. * @param secretKey A Facebook application secret key. * @throws NullPointerException If either parameter is {@code null}. * @throws IllegalArgumentException If either parameter is a blank string. * @deprecated You should use {@link #DefaultLegacyFacebookClient(String)} * instead. Facebook is moving to OAuth and will stop supporting * the old authentication scheme soon. */ @Deprecated public DefaultLegacyFacebookClient(String apiKey, String secretKey) { this(apiKey, secretKey, new DefaultWebRequestor(), new DefaultJsonMapper()); }
/** * Get user name from Facebook, but the code provided. * @param token Facebook access token * @return The user found in FB */ private User fetch(final String token) { try { return new DefaultFacebookClient( token, this.requestor, new DefaultJsonMapper(), Version.LATEST ).fetchObject( "me", User.class ); } catch (final FacebookException ex) { throw new IllegalArgumentException(ex); } }
/** * Get user name from Facebook, but the code provided. * @param token Facebook access token * @return The user found in FB */ private User fetch(final String token) { try { return new DefaultFacebookClient( token, this.requestor, new DefaultJsonMapper(), Version.LATEST ).fetchObject( "me", User.class ); } catch (final FacebookException ex) { throw new IllegalArgumentException(ex); } }
/** * Factory method which provides an instance with the given {@code name} and {@code value}. * <p> * The {@code value} parameter is often a {@link String} or primitive type like {@link Integer}, but you may pass in a * {@link java.util.List}, {@link java.util.Map}, or your own <tt>@Facebook</tt>-annotated Javabean and it will be * converted to JSON automatically. See the "attachment" section of * <a href="http://wiki.developers.facebook.com/index.php/Stream.publish">the stream.publish API documentation</a> for * an example of where this is useful. * * @param name * The parameter name. * @param value * The parameter value. * @return A {@code Parameter} instance with the given {@code name} and {@code value}. * @throws IllegalArgumentException * If {@code name} or {@code value} is {@code null} or a blank string. * @throws FacebookJsonMappingException * If an error occurs when converting {@code value} to JSON. */ public static Parameter with(String name, Object value) { return Parameter.with(name, value, new DefaultJsonMapper()); }
/** * Factory method which provides an instance with the given {@code name} and * {@code value}. * <p/> * The {@code value} parameter is often a {@link String} or primitive type * like {@link Integer}, but you may pass in a {@link java.util.List}, * {@link java.util.Map}, or your own <tt>@Facebook</tt>-annotated Javabean * and it will be converted to JSON automatically. See the "attachment" * section of <a * href="http://wiki.developers.facebook.com/index.php/Stream.publish">the * stream.publish API documentation</a> for an example of where this is * useful. * * @param name The parameter name. * @param value The parameter value. * @return A {@code Parameter} instance with the given {@code name} and * {@code value}. * @throws IllegalArgumentException If {@code name} or {@code value} is {@code null} or a blank * string. * @throws com.restfb.exception.FacebookJsonMappingException * If an error occurs when converting {@code value} to JSON. */ public static Parameter with(String name, Object value) { return Parameter.with(name, value, new DefaultJsonMapper()); }
User user = new User(); // RestFB entity of a Facebook User DefaultJsonMapper mapper = new DefaultJsonMapper(); String toJson = mapper.toJson(user);