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])); }
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 removeDomainWhitelisting(List<String> urls) throws FacebookException { requireNonNull(urls, "'urls' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.domain_whitelisting), Parameter.with(WHITELISTED_DOMAINS_PARAM_NAME, urls), Parameter.with(DOMAIN_ACTION_TYPE_PARAM_NAME, DomainActionTypeEnum.remove)); }
@Override public void addDomainWhitelisting(List<String> urls) throws FacebookException { requireNonNull(urls, "'urls' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.domain_whitelisting), Parameter.with(WHITELISTED_DOMAINS_PARAM_NAME, urls), Parameter.with(DOMAIN_ACTION_TYPE_PARAM_NAME, DomainActionTypeEnum.add)); }
@Override public void setPersistentMenu(List<CallToAction> callToActions) throws FacebookException { requireNonNull(callToActions, "'callToActions' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions), Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.existing_thread), Parameter.with(CALL_TO_ACTIONS_PARAM_NAME, callToActions)); }
@Override public void setGetStartedButton(CallToAction callToAction) throws FacebookException { requireNonNull(callToAction, "'callToAction' must not be null"); List<CallToAction> callToActions = Arrays.asList(callToAction); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions), Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.new_thread), Parameter.with(CALL_TO_ACTIONS_PARAM_NAME, callToActions)); }
@Override public void setAccountLinkingUrl(String url) throws FacebookException { requireNonNull(url, "'url' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.account_linking), Parameter.with(ACCOUNT_LINKING_URL_PARAM_NAME, url)); }
@Override public void setGreeting(Greeting greeting) throws FacebookException { requireNonNull(greeting, "'greeting' must not be null"); facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.greeting), Parameter.with(GREETING_PARAM_NAME, greeting)); }
@Override public void removeGreeting() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.greeting)); }
@Override public void removeAccountLinkingUrl() throws FacebookException { facebookClient.deleteObject(THREAD_SETTINGS_PATH, Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.account_linking)); }
@Override public SendResponse message(MessagingType type, MessageRecipient recipient, Message message, NotificationTypeEnum notificationType, MessageTag tag) throws FacebookException { requireNonNull(recipient, "'recipient' must not be null"); requireNonNull(message, "'message' must not be null"); return send(type, recipient, notificationType, tag, Parameter.with(MESSAGE_PARAM_NAME, message)); }
@Override public User getUserProfile(String userId, String fields) throws FacebookException { requireNonNull(userId, "'userId' must not be null"); return facebookClient.fetchObject(userId, User.class, Parameter.with(USER_FIELDS_PARAM_NAME, fields)); }
protected SendResponse send(MessageRecipient recipient, NotificationTypeEnum notificationType, MessageTag tag, Parameter... parameters) { requireNonNull(recipient, "'recipient' must not be null"); List<Parameter> params = new ArrayList<>(); params.add(Parameter.with(RECIPIENT_PARAM_NAME, recipient)); if (notificationType != null) { params.add(Parameter.with(NOTIFICATION_TYPE_PARAM_NAME, notificationType.name())); } if (tag != null) { params.add(Parameter.with(TAG_PARAM_NAME, tag.getTag())); } params.addAll(Arrays.asList(parameters)); return send(params.toArray(new Parameter[params.size()])); }
@Override public SendResponse senderAction(MessageRecipient recipient, SenderActionEnum senderAction, NotificationTypeEnum notificationType) throws FacebookException { requireNonNull(recipient, "'recipient' must not be null"); requireNonNull(senderAction, "'senderAction' must not be null"); return send(recipient, notificationType, null, Parameter.with(SENDER_ACTION_PARAM_NAME, senderAction.name())); }
@Override public DeviceCode fetchDeviceCode(ScopeBuilder scope) { verifyParameterPresence("scope", scope); if (accessToken == null) { throw new IllegalStateException("access token is required to fetch a device access token"); } String response = makeRequest("device/login", true, false, null, Parameter.with("type", "device_code"), Parameter.with("scope", scope.toString())); return jsonMapper.toJavaObject(response, DeviceCode.class); }
/** * @see com.restfb.FacebookClient#convertSessionKeysToAccessTokens(java.lang.String, java.lang.String, * java.lang.String[]) */ @Override public List<AccessToken> convertSessionKeysToAccessTokens(String appId, String secretKey, String... sessionKeys) { verifyParameterPresence("appId", appId); verifyParameterPresence("secretKey", secretKey); if (sessionKeys == null || sessionKeys.length == 0) { return emptyList(); } String json = makeRequest("/oauth/exchange_sessions", true, false, null, Parameter.with("client_id", appId), Parameter.with("client_secret", secretKey), Parameter.with("sessions", join(sessionKeys))); return jsonMapper.toJavaList(json, AccessToken.class); }
/** * @see com.restfb.FacebookClient#executeBatch(java.util.List, java.util.List) */ @Override public List<BatchResponse> executeBatch(List<BatchRequest> batchRequests, List<BinaryAttachment> binaryAttachments) { verifyParameterPresence("binaryAttachments", binaryAttachments); if (batchRequests == null || batchRequests.isEmpty()) { throw new IllegalArgumentException("You must specify at least one batch request."); } return jsonMapper.toJavaList( makeRequest("", true, false, binaryAttachments, Parameter.with("batch", jsonMapper.toJson(batchRequests, true))), BatchResponse.class); }
@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; }