ExtensibleClientpublic abstract class ExtensibleClient extends Object implements IFacebookRestClientBase class for interacting with the Facebook Application Programming Interface (API).
Most Facebook API methods map directly to function calls of this class.
Instances of FacebookRestClient should be initialized via calls to
{@link #auth_createToken}, followed by {@link #auth_getSession}.
For continually updated documentation, please refer to the
Developer Wiki. |
Fields Summary |
---|
public static URL | SERVER_URL | public static URL | HTTPS_SERVER_URL | protected final String | _secret | protected final String | _apiKey | protected final URL | _serverUrl | protected String | rawResponse | protected String | _sessionKey | protected boolean | _isDesktop | protected long | _userId | protected String | _sessionSecretfilled in when session is established
only used for desktop apps | public static int | NUM_AUTOAPPENDED_PARAMSThe number of parameters required for every request. | private static boolean | DEBUG | protected Boolean | _debug | protected File | _uploadFile | protected static final String | CRLF | protected static final String | PREF | protected static final int | UPLOAD_BUFFER_SIZE | public static final String | MARKETPLACE_STATUS_DEFAULT | public static final String | MARKETPLACE_STATUS_NOT_SUCCESS | public static final String | MARKETPLACE_STATUS_SUCCESS |
Constructors Summary |
---|
protected ExtensibleClient(URL serverUrl, String apiKey, String secret, String sessionKey)
_sessionKey = sessionKey;
_apiKey = apiKey;
_secret = secret;
_serverUrl = (null != serverUrl) ? serverUrl : SERVER_URL;
|
Methods Summary |
---|
public java.lang.String | auth_createToken()Call this function and store the result, using it to generate the
appropriate login url and then to retrieve the session information.
T d = this.callMethod(FacebookMethod.AUTH_CREATE_TOKEN);
return extractString(d);
| public abstract java.lang.String | auth_getSession(java.lang.String authToken)Call this function to retrieve the session information after your user has
logged in.
| public long | auth_getUserId(java.lang.String authToken)Call this function to get the user ID.
/*
* Get the session information if we don't have it; this will populate
* the user ID as well.
*/
if (null == this._sessionKey)
auth_getSession(authToken);
return this._userId;
| protected T | callMethod(com.facebook.api.IFacebookMethod method, com.facebook.api.Pair paramPairs)Call the specified method, with the given parameters, and return a DOM tree with the results.
return callMethod(method, Arrays.asList(paramPairs));
| protected T | callMethod(com.facebook.api.IFacebookMethod method, java.util.Collection paramPairs)Call the specified method, with the given parameters, and return a DOM tree with the results.
this.rawResponse = null;
HashMap<String, CharSequence> params =
new HashMap<String, CharSequence>(2 * method.numTotalParams());
params.put("method", method.methodName());
params.put("api_key", _apiKey);
params.put("v", TARGET_API_VERSION);
String format = getResponseFormat();
if (null != format) {
params.put("format", format);
}
if (method.requiresSession()) {
params.put("call_id", Long.toString(System.currentTimeMillis()));
params.put("session_key", _sessionKey);
}
CharSequence oldVal;
for (Pair<String, CharSequence> p : paramPairs) {
oldVal = params.put(p.first, p.second);
if (oldVal != null)
System.err.printf("For parameter %s, overwrote old value %s with new value %s.", p.first,
oldVal, p.second);
}
assert (!params.containsKey("sig"));
String signature =
generateSignature(FacebookSignatureUtil.convert(params.entrySet()), method.requiresSession());
params.put("sig", signature);
boolean doHttps = this.isDesktop() && FacebookMethod.AUTH_GET_SESSION.equals(method);
InputStream data =
method.takesFile() ? postFileRequest(method.methodName(), params) : postRequest(method.methodName(),
params,
doHttps,
true);
BufferedReader in = new BufferedReader(new InputStreamReader(data, "UTF-8"));
StringBuffer buffer = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
buffer.append(line);
}
String xmlResp = new String(buffer);
this.rawResponse = xmlResp;
return parseCallResult(new ByteArrayInputStream(xmlResp.getBytes("UTF-8")), method);
| private static java.lang.CharSequence | delimit(java.util.Collection iterable)
// could add a thread-safe version that uses StringBuffer as well
if (iterable == null || iterable.isEmpty())
return null;
StringBuilder buffer = new StringBuilder();
boolean notFirst = false;
for (Object item : iterable) {
if (notFirst)
buffer.append(",");
else
notFirst = true;
buffer.append(item.toString());
}
return buffer;
| protected static java.lang.CharSequence | delimit(java.util.Collection entries, java.lang.CharSequence delimiter, java.lang.CharSequence equals, boolean doEncode)
if (entries == null || entries.isEmpty())
return null;
StringBuilder buffer = new StringBuilder();
boolean notFirst = false;
for (Map.Entry<String, CharSequence> entry : entries) {
if (notFirst)
buffer.append(delimiter);
else
notFirst = true;
CharSequence value = entry.getValue();
buffer.append(entry.getKey()).append(equals).append(doEncode ? encode(value) : value);
}
return buffer;
| private static java.lang.String | encode(java.lang.CharSequence target)
if (target == null) {
return "";
}
String result = target.toString();
try {
result = URLEncoder.encode(result, "UTF8");
} catch (UnsupportedEncodingException e) {
System.err.printf("Unsuccessful attempt to encode '%s' into UTF8", result);
}
return result;
| public T | events_get(java.lang.Long userId, java.util.Collection eventIds, java.lang.Long startTime, java.lang.Long endTime)Returns all visible events according to the filters specified. This may be used to find all events of a user, or to query specific eids.
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(FacebookMethod.EVENTS_GET.numParams());
boolean hasUserId = null != userId && 0 != userId;
boolean hasEventIds = null != eventIds && !eventIds.isEmpty();
boolean hasStart = null != startTime && 0 != startTime;
boolean hasEnd = null != endTime && 0 != endTime;
if (hasUserId)
params.add(new Pair<String, CharSequence>("uid", Long.toString(userId)));
if (hasEventIds)
params.add(new Pair<String, CharSequence>("eids", delimit(eventIds)));
if (hasStart)
params.add(new Pair<String, CharSequence>("start_time", startTime.toString()));
if (hasEnd)
params.add(new Pair<String, CharSequence>("end_time", endTime.toString()));
return this.callMethod(FacebookMethod.EVENTS_GET, params);
| public T | events_getMembers(java.lang.Number eventId)Retrieves the membership list of an event
assert (null != eventId);
return this.callMethod(FacebookMethod.EVENTS_GET_MEMBERS,
new Pair<String, CharSequence>("eid", eventId.toString()));
| protected boolean | extractBoolean(T result)Extracts a Boolean from a result that consists of a Boolean only.
return 1 == extractInt(result);
| protected abstract int | extractInt(T result)Extracts an Long from a result that consists of an Long only.
| protected abstract java.lang.Long | extractLong(T result)Extracts an Long from a result that consists of a Long only.
| protected abstract java.lang.String | extractString(T result)Extracts a String from a T consisting entirely of a String.
| protected abstract java.net.URL | extractURL(T result)Extracts a URL from a result that consists of a URL only.
| public boolean | fbml_refreshImgSrc(java.lang.String imageUrl)Recaches the image with the specified imageUrl.
return fbml_refreshImgSrc(new URL(imageUrl));
| public boolean | fbml_refreshImgSrc(java.net.URL imageUrl)Recaches the image with the specified imageUrl.
return extractBoolean(this.callMethod(FacebookMethod.FBML_REFRESH_IMG_SRC,
new Pair<String, CharSequence>("url",
imageUrl.toString())));
| public boolean | fbml_refreshRefUrl(java.net.URL url)Recaches the referenced url.
return extractBoolean(this.callMethod(FacebookMethod.FBML_REFRESH_REF_URL,
new Pair<String, CharSequence>("url", url.toString())));
| public boolean | fbml_refreshRefUrl(java.lang.String url)Recaches the referenced url.
return fbml_refreshRefUrl(new URL(url));
| public boolean | fbml_setRefHandle(java.lang.String handle, java.lang.String fbmlMarkup)Associates a "handle " with FBML markup so that the handle can be used within the
fb:ref FBML tag.
A handle is unique within an application and allows an application to publish identical FBML
to many user profiles and do subsequent updates without having to republish FBML for each user.
return extractBoolean(this.callMethod(FacebookMethod.FBML_SET_REF_HANDLE,
new Pair<String, CharSequence>("handle", handle),
new Pair<String, CharSequence>("fbml", fbmlMarkup)));
| protected boolean | feedHandler(com.facebook.api.IFacebookMethod feedMethod, java.lang.CharSequence title, java.lang.CharSequence body, java.util.Collection images, java.lang.Integer priority)Helper function: assembles the parameters used by feed_publishActionOfUser and
feed_publishStoryToUser
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(feedMethod.numParams());
params.add(new Pair<String, CharSequence>("title", title));
if (null != body)
params.add(new Pair<String, CharSequence>("body", body));
if (null != priority)
params.add(new Pair<String, CharSequence>("priority", priority.toString()));
handleFeedImages(params, images);
return extractBoolean(this.callMethod(feedMethod, params));
| public boolean | feed_PublishTemplatizedAction(com.facebook.api.TemplatizedAction action)
return this.templatizedFeedHandler(FacebookMethod.FEED_PUBLISH_TEMPLATIZED_ACTION, action.getTitleTemplate(), action.getTitleParams(),
action.getBodyTemplate(), action.getBodyParams(), action.getBodyGeneral(), action.getPictures(), action.getTargetIds());
| public boolean | feed_publishActionOfUser(java.lang.CharSequence title, java.lang.CharSequence body)Publish the notification of an action taken by a user to newsfeed.
return feed_publishActionOfUser(title, body, null);
| public boolean | feed_publishActionOfUser(java.lang.CharSequence title, java.lang.CharSequence body, java.util.Collection images)Publish the notification of an action taken by a user to newsfeed.
return feedHandler(FacebookMethod.FEED_PUBLISH_ACTION_OF_USER, title, body, images, null);
| public boolean | feed_publishStoryToUser(java.lang.CharSequence title, java.lang.CharSequence body)Publish a story to the logged-in user's newsfeed.
return feed_publishStoryToUser(title, body, null, null);
| public boolean | feed_publishStoryToUser(java.lang.CharSequence title, java.lang.CharSequence body, java.util.Collection images)Publish a story to the logged-in user's newsfeed.
return feed_publishStoryToUser(title, body, images, null);
| public boolean | feed_publishStoryToUser(java.lang.CharSequence title, java.lang.CharSequence body, java.lang.Integer priority)Publish a story to the logged-in user's newsfeed.
return feed_publishStoryToUser(title, body, null, priority);
| public boolean | feed_publishStoryToUser(java.lang.CharSequence title, java.lang.CharSequence body, java.util.Collection images, java.lang.Integer priority)Publish a story to the logged-in user's newsfeed.
return feedHandler(FacebookMethod.FEED_PUBLISH_STORY_TO_USER, title, body, images, priority);
| public boolean | feed_publishTemplatizedAction(java.lang.Long actorId, java.lang.CharSequence titleTemplate)Publishes a Mini-Feed story describing an action taken by a user, and
publishes aggregating News Feed stories to the friends of that user.
Stories are identified as being combinable if they have matching templates and substituted values.
return feed_publishTemplatizedAction(actorId, titleTemplate, null, null, null, null, null, null );
| public boolean | feed_publishTemplatizedAction(java.lang.Long actorId, java.lang.CharSequence titleTemplate, java.util.Map titleData, java.lang.CharSequence bodyTemplate, java.util.Map bodyData, java.lang.CharSequence bodyGeneral, java.util.Collection targetIds, java.util.Collection images)Publishes a Mini-Feed story describing an action taken by a user, and
publishes aggregating News Feed stories to the friends of that user.
Stories are identified as being combinable if they have matching templates and substituted values.
assert null != actorId && actorId > 0 : "Invalid actorId: " + Long.toString(actorId);
assert null != titleTemplate && !"".equals(titleTemplate);
FacebookMethod method = FacebookMethod.FEED_PUBLISH_TEMPLATIZED_ACTION;
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(method.numParams());
params.add(new Pair<String, CharSequence>("actor_id", actorId.toString()));
params.add(new Pair<String, CharSequence>("title_template", titleTemplate));
if (null != titleData && !titleData.isEmpty()) {
JSONObject titleDataJson = new JSONObject();
for (String key : titleData.keySet()) {
try {
titleDataJson.put(key, titleData.get(key));
}
catch (Exception ignored) {}
}
params.add(new Pair<String, CharSequence>("title_data", titleDataJson.toString()));
}
if (null != bodyTemplate && !"".equals(bodyTemplate)) {
params.add(new Pair<String, CharSequence>("body_template", bodyTemplate));
if (null != bodyData && !bodyData.isEmpty()) {
JSONObject bodyDataJson = new JSONObject();
for (String key : bodyData.keySet()) {
try {
bodyDataJson.put(key, bodyData.get(key));
}
catch (Exception ignored) {}
}
params.add(new Pair<String, CharSequence>("body_data", bodyDataJson.toString()));
}
}
if (null != bodyTemplate && !"".equals(bodyTemplate)) {
params.add(new Pair<String, CharSequence>("body_template", bodyTemplate));
}
if (null != targetIds && !targetIds.isEmpty()) {
params.add(new Pair<String, CharSequence>("target_ids", delimit(targetIds)));
}
handleFeedImages(params, images);
return extractBoolean(this.callMethod(method, params));
| public boolean | feed_publishTemplatizedAction(java.lang.Integer actorId, java.lang.CharSequence titleTemplate, java.util.Map titleData, java.lang.CharSequence bodyTemplate, java.util.Map bodyData, java.lang.CharSequence bodyGeneral, java.util.Collection targetIds, java.util.Collection images)
return this.feed_publishTemplatizedAction((long)actorId.intValue(), titleTemplate,
titleData, bodyTemplate, bodyData, bodyGeneral, targetIds, images);
| public boolean | feed_publishTemplatizedAction(java.lang.String titleTemplate, java.lang.String titleData, java.lang.String bodyTemplate, java.lang.String bodyData, java.lang.String bodyGeneral, java.util.Collection pictures, java.lang.String targetIds)
return this.templatizedFeedHandler(FacebookMethod.FEED_PUBLISH_TEMPLATIZED_ACTION, titleTemplate, titleData,
bodyTemplate, bodyData, bodyGeneral, pictures, targetIds);
| public T | fql_query(java.lang.CharSequence query)Retrieves the results of a Facebook Query Language query
assert (null != query);
return this.callMethod(FacebookMethod.FQL_QUERY,
new Pair<String, CharSequence>("query", query));
| public T | friends_areFriends(long userId1, long userId2)Retrieves whether two users are friends.
return this.callMethod(FacebookMethod.FRIENDS_ARE_FRIENDS,
new Pair<String, CharSequence>("uids1", Long.toString(userId1)),
new Pair<String, CharSequence>("uids2", Long.toString(userId2)));
| public T | friends_areFriends(java.util.Collection userIds1, java.util.Collection userIds2)Retrieves whether pairs of users are friends.
Returns whether the first user in userIds1 is friends with the first user in
userIds2 , the second user in userIds1 is friends with the second user in
userIds2 , etc.
if (userIds1 == null || userIds2 == null || userIds1.isEmpty() || userIds2.isEmpty()) {
throw new IllegalArgumentException("Collections passed to friends_areFriends should not be null or empty");
}
if (userIds1.size() != userIds2.size()) {
throw new IllegalArgumentException(String.format("Collections should be same size: got userIds1: %d elts; userIds2: %d elts",
userIds1.size(), userIds2.size()));
}
return this.callMethod(FacebookMethod.FRIENDS_ARE_FRIENDS,
new Pair<String, CharSequence>("uids1", delimit(userIds1)),
new Pair<String, CharSequence>("uids2", delimit(userIds2)));
| public T | friends_get()Retrieves the friends of the currently logged in user.
return this.callMethod(FacebookMethod.FRIENDS_GET);
| public T | friends_getAppUsers()Retrieves the friends of the currently logged in user, who are also users
of the calling application.
return this.callMethod(FacebookMethod.FRIENDS_GET_APP_USERS);
| private java.lang.String | generateSignature(java.util.List params, boolean requiresSession)
String secret = (isDesktop() && requiresSession) ? this._sessionSecret : this._secret;
return FacebookSignatureUtil.generateSignature(params, secret);
| public java.lang.String | getRawResponse()
return this.rawResponse;
| public java.lang.String | getResponseFormat()The response format in which results to FacebookMethod calls are returned
return null;
| public java.lang.Object | getResponsePOJO()
if (this.rawResponse == null) {
return null;
}
if ((this.getResponseFormat() != null) && (! "xml".equals(this.getResponseFormat().toLowerCase()))) {
//JAXB will not work with JSON
throw new RuntimeException("You can only generate a response POJO when using XML formatted API responses! JSON users go elsewhere!");
}
JAXBContext jc;
Object pojo = null;
try {
jc = JAXBContext.newInstance("com.facebook.api.schema");
Unmarshaller unmarshaller = jc.createUnmarshaller();
pojo = unmarshaller.unmarshal(new ByteArrayInputStream(this.rawResponse.getBytes("UTF-8")));
} catch (JAXBException e) {
System.err.println("getResponsePOJO() - Could not unmarshall XML stream into POJO");
e.printStackTrace();
}
catch (NullPointerException e) {
System.err.println("getResponsePOJO() - Could not unmarshall XML stream into POJO.");
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
System.err.println("getResponsePOJO() - Could not unmarshall XML stream into POJO.");
e.printStackTrace();
}
return pojo;
| public T | groups_get(java.lang.Long userId, java.util.Collection groupIds)Retrieves the groups associated with a user
boolean hasGroups = (null != groupIds && !groupIds.isEmpty());
if (null != userId)
return hasGroups ?
this.callMethod(FacebookMethod.GROUPS_GET, new Pair<String, CharSequence>("uid",
userId.toString()),
new Pair<String, CharSequence>("gids", delimit(groupIds))) :
this.callMethod(FacebookMethod.GROUPS_GET,
new Pair<String, CharSequence>("uid", userId.toString()));
else
return hasGroups ?
this.callMethod(FacebookMethod.GROUPS_GET, new Pair<String, CharSequence>("gids",
delimit(groupIds))) :
this.callMethod(FacebookMethod.GROUPS_GET);
| public T | groups_getMembers(java.lang.Number groupId)Retrieves the membership list of a group
assert (null != groupId);
return this.callMethod(FacebookMethod.GROUPS_GET_MEMBERS,
new Pair<String, CharSequence>("gid", groupId.toString()));
| protected void | handleFeedImages(java.util.List params, java.util.Collection images)Adds image parameters
if (images != null && images.size() > 4) {
throw new IllegalArgumentException("At most four images are allowed, got " + Integer.toString(images.size()));
}
if (null != images && !images.isEmpty()) {
int image_count = 0;
for (IPair image : images) {
++image_count;
assert null != image.getFirst() : "Image URL must be provided";
params.add(new Pair<String, CharSequence>(String.format("image_%d", image_count),
image.getFirst().toString()));
if (null != image.getSecond())
params.add(new Pair<String, CharSequence>(String.format("image_%d_link", image_count),
image.getSecond().toString()));
}
}
| public boolean | isDebug()
return (null == _debug) ? DEBUG : _debug.booleanValue();
| public boolean | isDesktop()
return this._isDesktop;
| protected void | log(java.lang.CharSequence message)Logs a message. Override this for more detailed logging.
System.out.println(message);
| protected final void | logException(java.lang.Exception e)Logs an exception with default message
logException("exception", e);
| protected void | logException(java.lang.CharSequence msg, java.lang.Exception e)Logs an exception with an introductory message in addition to the
exception's getMessage().
System.err.println(msg + ":" + e.getMessage());
e.printStackTrace();
| public java.lang.Long | marketplace_createListing(java.lang.Long listingId, boolean showOnProfile, com.facebook.api.MarketListing listing)
return this.marketplace_createListing(listingId, showOnProfile, listing.getAttribs());
| public java.lang.Long | marketplace_createListing(boolean showOnProfile, com.facebook.api.MarketListing listing)
return this.marketplace_createListing(null, showOnProfile, listing.getAttribs());
| public java.lang.Long | marketplace_createListing(java.lang.Boolean showOnProfile, com.facebook.api.MarketplaceListing attrs)Create a marketplace listing
T result = this.callMethod(FacebookMethod.MARKETPLACE_CREATE_LISTING,
new Pair<String, CharSequence>("show_on_profile", showOnProfile ? "1" : "0"),
new Pair<String, CharSequence>("listing_id", "0"),
new Pair<String, CharSequence>("listing_attrs", attrs.jsonify().toString()));
return this.extractLong(result);
| public java.lang.Long | marketplace_createListing(java.lang.Long listingId, boolean showOnProfile, java.lang.String attributes)
T result = this.callMethod(FacebookMethod.MARKETPLACE_CREATE_LISTING,
new Pair<String, CharSequence>("show_on_profile", showOnProfile ? "1" : "0"),
new Pair<String, CharSequence>("listing_id", "0"),
new Pair<String, CharSequence>("listing_attrs", attributes));
return this.extractLong(result);
| public java.lang.Long | marketplace_editListing(java.lang.Long listingId, java.lang.Boolean showOnProfile, com.facebook.api.MarketListing attrs)
T result = this.callMethod(FacebookMethod.MARKETPLACE_CREATE_LISTING,
new Pair<String, CharSequence>("show_on_profile", showOnProfile ? "1" : "0"),
new Pair<String, CharSequence>("listing_id", listingId.toString()),
new Pair<String, CharSequence>("listing_attrs", attrs.getAttribs()));
return this.extractLong(result);
| public java.lang.Long | marketplace_editListing(java.lang.Long listingId, java.lang.Boolean showOnProfile, com.facebook.api.MarketplaceListing attrs)Modify a marketplace listing
T result = this.callMethod(FacebookMethod.MARKETPLACE_CREATE_LISTING,
new Pair<String, CharSequence>("show_on_profile", showOnProfile ? "1" : "0"),
new Pair<String, CharSequence>("listing_id", listingId.toString()),
new Pair<String, CharSequence>("listing_attrs", attrs.jsonify().toString()));
return this.extractLong(result);
| public java.util.List | marketplace_getCategories()Get the categories available in marketplace.
T temp = this.callMethod(FacebookMethod.MARKETPLACE_GET_CATEGORIES);
List<String> results = new ArrayList<String>();
if (temp instanceof Document) {
Document d = (Document)temp;
NodeList cats = d.getElementsByTagName("marketplace_category");
for (int count = 0; count < cats.getLength(); count++) {
results.add(cats.item(count).getFirstChild().getTextContent());
}
}
else {
JSONObject j = (JSONObject)temp;
Iterator it = j.keys();
while (it.hasNext()) {
try {
results.add(j.get((String)it.next()).toString());
}
catch (Exception ignored) { }
}
}
return results;
| public T | marketplace_getCategoriesObject()Get the categories available in marketplace.
T temp = this.callMethod(FacebookMethod.MARKETPLACE_GET_CATEGORIES);
return temp;
| public T | marketplace_getListings(java.util.Collection listingIds, java.util.Collection userIds)Fetch marketplace listings, filtered by listing IDs and/or the posting users' IDs.
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(FacebookMethod.MARKETPLACE_GET_LISTINGS.numParams());
if (null != listingIds && !listingIds.isEmpty()) {
params.add(new Pair<String, CharSequence>("listing_ids", delimit(listingIds)));
}
if (null != userIds && !userIds.isEmpty()) {
params.add(new Pair<String, CharSequence>("uids", delimit(userIds)));
}
assert !params.isEmpty() : "Either listingIds or userIds should be provided";
return this.callMethod(FacebookMethod.MARKETPLACE_GET_LISTINGS, params);
| public T | marketplace_getSubCategories(java.lang.CharSequence category)Get the subcategories available for a category.
return this.callMethod(FacebookMethod.MARKETPLACE_GET_SUBCATEGORIES,
new Pair<String, CharSequence>("category", category));
| public boolean | marketplace_removeListing(java.lang.Long listingId, com.facebook.api.MarketListingStatus status)
return this.marketplace_removeListing(listingId, status.getName());
| public boolean | marketplace_removeListing(java.lang.Long listingId)Remove a marketplace listing
return marketplace_removeListing(listingId, MARKETPLACE_STATUS_DEFAULT);
| public boolean | marketplace_removeListing(java.lang.Long listingId, java.lang.CharSequence status)Remove a marketplace listing
assert MARKETPLACE_STATUS_DEFAULT.equals(status) || MARKETPLACE_STATUS_SUCCESS.equals(status)
|| MARKETPLACE_STATUS_NOT_SUCCESS.equals(status) : "Invalid status: " + status;
T result = this.callMethod(FacebookMethod.MARKETPLACE_REMOVE_LISTING,
new Pair<String, CharSequence>("listing_id", listingId.toString()),
new Pair<String, CharSequence>("status", status));
return this.extractBoolean(result);
| public T | marketplace_search(java.lang.CharSequence category, java.lang.CharSequence subCategory, java.lang.CharSequence query)Search for marketplace listings, optionally by category, subcategory, and/or query string.
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(FacebookMethod.MARKETPLACE_SEARCH.numParams());
if (null != category && !"".equals(category)) {
params.add(new Pair<String, CharSequence>("category", category));
if (null != subCategory && !"".equals(subCategory)) {
params.add(new Pair<String, CharSequence>("subcategory", subCategory));
}
}
if (null != query && !"".equals(query)) {
params.add(new Pair<String, CharSequence>("query", category));
}
return this.callMethod(FacebookMethod.MARKETPLACE_SEARCH, params);
| public T | notifications_get()Retrieves the outstanding notifications for the session user.
return this.callMethod(FacebookMethod.NOTIFICATIONS_GET);
| public java.net.URL | notifications_send(java.util.Collection recipientIds, java.lang.CharSequence notification, java.lang.CharSequence email)Send a notification message to the specified users.
assert (null != recipientIds && !recipientIds.isEmpty());
assert (null != notification);
ArrayList<Pair<String, CharSequence>> args = new ArrayList<Pair<String, CharSequence>>(3);
args.add(new Pair<String, CharSequence>("to_ids", delimit(recipientIds)));
args.add(new Pair<String, CharSequence>("notification", notification));
if (null != email) {
args.add(new Pair<String, CharSequence>("email", email));
}
T result = this.callMethod(FacebookMethod.NOTIFICATIONS_SEND, args);
return extractURL(result);
| public T | pages_getInfo(java.util.Collection pageIds, java.util.EnumSet fields)Retrieves the requested profile fields for the Facebook Pages with the given
pageIds . Can be called for pages that have added the application
without establishing a session.
if (pageIds == null || pageIds.isEmpty()) {
throw new IllegalArgumentException("pageIds cannot be empty or null");
}
if (fields == null || fields.isEmpty()) {
throw new IllegalArgumentException("fields cannot be empty or null");
}
IFacebookMethod method =
null == this._sessionKey ? FacebookMethod.PAGES_GET_INFO_NO_SESSION : FacebookMethod.PAGES_GET_INFO;
return this.callMethod(method,
new Pair<String, CharSequence>("page_ids", delimit(pageIds)),
new Pair<String, CharSequence>("fields", delimit(fields)));
| public T | pages_getInfo(java.util.Collection pageIds, java.util.Set fields)Retrieves the requested profile fields for the Facebook Pages with the given
pageIds . Can be called for pages that have added the application
without establishing a session.
if (pageIds == null || pageIds.isEmpty()) {
throw new IllegalArgumentException("pageIds cannot be empty or null");
}
if (fields == null || fields.isEmpty()) {
throw new IllegalArgumentException("fields cannot be empty or null");
}
IFacebookMethod method =
null == this._sessionKey ? FacebookMethod.PAGES_GET_INFO_NO_SESSION : FacebookMethod.PAGES_GET_INFO;
return this.callMethod(method,
new Pair<String, CharSequence>("page_ids", delimit(pageIds)),
new Pair<String, CharSequence>("fields", delimit(fields)));
| public T | pages_getInfo(java.lang.Long userId, java.util.EnumSet fields)Retrieves the requested profile fields for the Facebook Pages of the user with the given
userId .
if (fields == null || fields.isEmpty()) {
throw new IllegalArgumentException("fields cannot be empty or null");
}
if (userId == null) {
userId = this._userId;
}
return this.callMethod(FacebookMethod.PAGES_GET_INFO,
new Pair<String, CharSequence>("uid", userId.toString()),
new Pair<String, CharSequence>("fields", delimit(fields)));
| public T | pages_getInfo(java.lang.Long userId, java.util.Set fields)Retrieves the requested profile fields for the Facebook Pages of the user with the given
userId .
if (fields == null || fields.isEmpty()) {
throw new IllegalArgumentException("fields cannot be empty or null");
}
if (userId == null) {
userId = this._userId;
}
return this.callMethod(FacebookMethod.PAGES_GET_INFO,
new Pair<String, CharSequence>("uid", userId.toString()),
new Pair<String, CharSequence>("fields", delimit(fields)));
| public boolean | pages_isAdmin(java.lang.Long pageId)Checks whether the logged-in user for this session is an admin of the page
with the given pageId .
return extractBoolean(this.callMethod(FacebookMethod.PAGES_IS_ADMIN,
new Pair<String, CharSequence>("page_id",
pageId.toString())));
| public boolean | pages_isAppAdded(java.lang.Long pageId)Checks whether a page has added the application
return extractBoolean(this.callMethod(FacebookMethod.PAGES_IS_APP_ADDED,
new Pair<String,CharSequence>("page_id", pageId.toString())));
| public boolean | pages_isFan(java.lang.Long pageId, java.lang.Long userId)Checks whether a user is a fan of the page with the given pageId .
return extractBoolean(this.callMethod(FacebookMethod.PAGES_IS_FAN,
new Pair<String,CharSequence>("page_id", pageId.toString()),
new Pair<String,CharSequence>("uid", userId.toString())));
| public boolean | pages_isFan(java.lang.Long pageId)Checks whether the logged-in user is a fan of the page with the given pageId .
return extractBoolean(this.callMethod(FacebookMethod.PAGES_IS_FAN,
new Pair<String,CharSequence>("page_id", pageId.toString())));
| protected abstract T | parseCallResult(java.io.InputStream data, com.facebook.api.IFacebookMethod method)Parses the result of an API call into a T.
| private boolean | photos_addTag(java.lang.Long photoId, java.lang.Double xPct, java.lang.Double yPct, java.lang.Long taggedUserId, java.lang.CharSequence tagText)
assert (null != photoId && !photoId.equals(0));
assert (null != taggedUserId || null != tagText);
assert (null != xPct && xPct >= 0 && xPct <= 100);
assert (null != yPct && yPct >= 0 && yPct <= 100);
T d =
this.callMethod(FacebookMethod.PHOTOS_ADD_TAG, new Pair<String, CharSequence>("pid", photoId.toString()),
new Pair<String, CharSequence>("tag_uid", taggedUserId.toString()),
new Pair<String, CharSequence>("x", xPct.toString()),
new Pair<String, CharSequence>("y", yPct.toString()));
return extractBoolean(d);
| public boolean | photos_addTag(java.lang.Long photoId, java.lang.CharSequence tagText, java.lang.Double xPct, java.lang.Double yPct)Adds a tag to a photo.
return photos_addTag(photoId, xPct, yPct, null, tagText);
| public boolean | photos_addTag(java.lang.Long photoId, java.lang.Long taggedUserId, java.lang.Double xPct, java.lang.Double yPct)Adds a tag to a photo.
return photos_addTag(photoId, xPct, yPct, taggedUserId, null);
| public T | photos_addTags(java.lang.Long photoId, java.util.Collection tags)Adds several tags to a photo.
assert (photoId > 0);
assert (null != tags && !tags.isEmpty());
JSONArray jsonTags=new JSONArray();
for (PhotoTag tag : tags) {
jsonTags.put(tag.jsonify());
}
return this.callMethod(FacebookMethod.PHOTOS_ADD_TAG,
new Pair<String, CharSequence>("pid", photoId.toString()),
new Pair<String, CharSequence>("tags", jsonTags.toString()));
| public T | photos_createAlbum(java.lang.String albumName)Creates an album.
return this.photos_createAlbum(albumName, null /*description*/, null /*location*/);
| public T | photos_createAlbum(java.lang.String name, java.lang.String description, java.lang.String location)Creates an album.
assert (null != name && !"".equals(name));
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(FacebookMethod.PHOTOS_CREATE_ALBUM.numParams());
params.add(new Pair<String, CharSequence>("name", name));
if (null != description)
params.add(new Pair<String, CharSequence>("description", description));
if (null != location)
params.add(new Pair<String, CharSequence>("location", location));
return this.callMethod(FacebookMethod.PHOTOS_CREATE_ALBUM, params);
| public T | photos_get(java.util.Collection photoIds)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
return photos_get(null /*subjId*/, null /*albumId*/, photoIds);
| public T | photos_get(java.lang.Long subjId, java.lang.Long albumId)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
return photos_get(subjId, albumId, null /*photoIds*/);
| public T | photos_get(java.lang.Long subjId, java.util.Collection photoIds)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
return photos_get(subjId, null /*albumId*/, photoIds);
| public T | photos_get(java.lang.Long subjId)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
return photos_get(subjId, null /*albumId*/, null /*photoIds*/);
| public T | photos_get(java.lang.Long subjId, java.lang.Long albumId, java.util.Collection photoIds)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(FacebookMethod.PHOTOS_GET.numParams());
boolean hasUserId = null != subjId && 0 != subjId;
boolean hasAlbumId = null != albumId && 0 != albumId;
boolean hasPhotoIds = null != photoIds && !photoIds.isEmpty();
if (!hasUserId && !hasAlbumId && !hasPhotoIds) {
throw new IllegalArgumentException("At least one of photoIds, albumId, or subjId must be provided");
}
if (hasUserId)
params.add(new Pair<String, CharSequence>("subj_id", Long.toString(subjId)));
if (hasAlbumId)
params.add(new Pair<String, CharSequence>("aid", Long.toString(albumId)));
if (hasPhotoIds)
params.add(new Pair<String, CharSequence>("pids", delimit(photoIds)));
return this.callMethod(FacebookMethod.PHOTOS_GET, params);
| public T | photos_getAlbums(java.util.Collection albumIds)Retrieves album metadata for a list of album IDs.
return photos_getAlbums(null /*userId*/, albumIds);
| public T | photos_getAlbums(java.lang.Long userId)Retrieves album metadata for albums owned by a user.
return photos_getAlbums(userId, null /*albumIds*/);
| public T | photos_getAlbums(java.lang.Long userId, java.util.Collection albumIds)Retrieves album metadata. Pass a user id and/or a list of album ids to specify the albums
to be retrieved (at least one must be provided)
boolean hasUserId = null != userId && userId != 0;
boolean hasAlbumIds = null != albumIds && !albumIds.isEmpty();
assert (hasUserId || hasAlbumIds); // one of the two must be provided
if (hasUserId)
return (hasAlbumIds) ?
this.callMethod(FacebookMethod.PHOTOS_GET_ALBUMS, new Pair<String, CharSequence>("uid",
Long.toString(userId)),
new Pair<String, CharSequence>("aids", delimit(albumIds))) :
this.callMethod(FacebookMethod.PHOTOS_GET_ALBUMS,
new Pair<String, CharSequence>("uid", Long.toString(userId)));
else
return this.callMethod(FacebookMethod.PHOTOS_GET_ALBUMS,
new Pair<String, CharSequence>("aids", delimit(albumIds)));
| public T | photos_getByAlbum(java.lang.Long albumId, java.util.Collection photoIds)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
return photos_get(null /*subjId*/, albumId, photoIds);
| public T | photos_getByAlbum(java.lang.Long albumId)Used to retrieve photo objects using the search parameters (one or more of the
parameters must be provided).
return photos_get(null /*subjId*/, albumId, null /*photoIds*/);
| public T | photos_getTags(java.util.Collection photoIds)Retrieves the tags for the given set of photos.
return this.callMethod(FacebookMethod.PHOTOS_GET_TAGS,
new Pair<String, CharSequence>("pids", delimit(photoIds)));
| public T | photos_upload(java.io.File photo)Uploads a photo to Facebook.
return photos_upload(photo, null /* caption */ , null /* albumId */);
| public T | photos_upload(java.io.File photo, java.lang.String caption)Uploads a photo to Facebook.
return photos_upload(photo, caption, null /* albumId */);
| public T | photos_upload(java.io.File photo, java.lang.Long albumId)Uploads a photo to Facebook.
return photos_upload(photo, null /* caption */, albumId);
| public T | photos_upload(java.io.File photo, java.lang.String caption, java.lang.Long albumId)Uploads a photo to Facebook.
ArrayList<Pair<String, CharSequence>> params =
new ArrayList<Pair<String, CharSequence>>(FacebookMethod.PHOTOS_UPLOAD.numParams());
assert (photo.exists() && photo.canRead());
this._uploadFile = photo;
if (null != albumId)
params.add(new Pair<String, CharSequence>("aid", Long.toString(albumId)));
if (null != caption)
params.add(new Pair<String, CharSequence>("caption", caption));
return callMethod(FacebookMethod.PHOTOS_UPLOAD, params);
| protected java.io.InputStream | postFileRequest(java.lang.String methodName, java.util.Map params)Helper function for posting a request that includes raw file data, eg {@link #photos_upload}.
assert (null != _uploadFile);
try {
BufferedInputStream bufin = new BufferedInputStream(new FileInputStream(_uploadFile));
String boundary = Long.toString(System.currentTimeMillis(), 16);
URLConnection con = SERVER_URL.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
con.setRequestProperty("MIME-version", "1.0");
DataOutputStream out = new DataOutputStream(con.getOutputStream());
for (Map.Entry<String, CharSequence> entry : params.entrySet()) {
out.writeBytes(PREF + boundary + CRLF);
out.writeBytes("Content-disposition: form-data; name=\"" + entry.getKey() + "\"");
out.writeBytes(CRLF + CRLF);
out.writeBytes(entry.getValue().toString());
out.writeBytes(CRLF);
}
out.writeBytes(PREF + boundary + CRLF);
out.writeBytes("Content-disposition: form-data; filename=\"" + _uploadFile.getName() + "\"" +
CRLF);
out.writeBytes("Content-Type: image/jpeg" + CRLF);
// out.writeBytes("Content-Transfer-Encoding: binary" + CRLF); // not necessary
// Write the file
out.writeBytes(CRLF);
byte b[] = new byte[UPLOAD_BUFFER_SIZE];
int byteCounter = 0;
int i;
while (-1 != (i = bufin.read(b))) {
byteCounter += i;
out.write(b, 0, i);
}
out.writeBytes(CRLF + PREF + boundary + PREF + CRLF);
out.flush();
out.close();
InputStream is = con.getInputStream();
return is;
} catch (Exception e) {
logException(e);
return null;
}
| private java.io.InputStream | postRequest(java.lang.CharSequence method, java.util.Map params, boolean doHttps, boolean doEncode)
CharSequence buffer = (null == params) ? "" : delimit(params.entrySet(), "&", "=", doEncode);
URL serverUrl = (doHttps) ? HTTPS_SERVER_URL : _serverUrl;
if (isDebug()) {
StringBuilder debugMsg = new StringBuilder()
.append(method)
.append(" POST: ")
.append(serverUrl.toString())
.append("?");
debugMsg.append(buffer);
log(debugMsg);
}
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();
try {
conn.setRequestMethod("POST");
} catch (ProtocolException ex) {
logException(ex);
}
conn.setDoOutput(true);
conn.connect();
conn.getOutputStream().write(buffer.toString().getBytes());
return conn.getInputStream();
| public T | profile_getFBML(java.lang.Long userId)Gets the FBML for a user's profile, including the content for both the profile box
and the profile actions.
return this.callMethod(FacebookMethod.PROFILE_GET_FBML,
new Pair<String, CharSequence>("uid", Long.toString(userId)));
| public boolean | profile_setFBML(java.lang.CharSequence fbmlMarkup, java.lang.Long userId)Sets the FBML for a user's profile, including the content for both the profile box
and the profile actions.
return extractBoolean(this.callMethod(FacebookMethod.PROFILE_SET_FBML,
new Pair<String, CharSequence>("uid",
Long.toString(userId)),
new Pair<String, CharSequence>("markup", fbmlMarkup)));
| public void | setDebug(boolean isDebug)
_debug = isDebug;
| public static void | setDebugAll(boolean isDebug)
ExtensibleClient.DEBUG = isDebug;
| public void | setIsDesktop(boolean isDesktop)
this._isDesktop = isDesktop;
| public boolean | sms_canSend()
return this.sms_canSend(this.users_getLoggedInUser());
| public boolean | sms_canSend(java.lang.Long userId)Determines whether this application can send SMS to the user identified by userId
return extractBoolean(this.callMethod(FacebookMethod.SMS_CAN_SEND,
new Pair<String, CharSequence>("uid",
userId.toString())));
| public void | sms_sendMessage(java.lang.Long userId, java.lang.CharSequence message)Sends a message via SMS to the user identified by userId .
The SMS extended permission is required for success.
this.callMethod(FacebookMethod.SMS_SEND_MESSAGE,
new Pair<String, CharSequence>("uid", userId.toString()),
new Pair<String, CharSequence>("message", message),
new Pair<String, CharSequence>("req_session", "0"));
| public int | sms_sendMessageWithSession(java.lang.Long userId, java.lang.CharSequence message)Sends a message via SMS to the user identified by userId , with
the expectation that the user will reply. The SMS extended permission is required for success.
The returned mobile session ID can be stored and used in {@link #sms_sendResponse} when
the user replies.
return extractInt(this.callMethod(FacebookMethod.SMS_SEND_MESSAGE,
new Pair<String, CharSequence>("uid", userId.toString()),
new Pair<String, CharSequence>("message", message),
new Pair<String, CharSequence>("req_session", "1")));
| public void | sms_sendResponse(java.lang.Integer userId, java.lang.CharSequence response, java.lang.Integer mobileSessionId)Sends a message via SMS to the user identified by userId in response
to a user query associated with mobileSessionId .
this.callMethod(FacebookMethod.SMS_SEND_MESSAGE,
new Pair<String, CharSequence>("uid", userId.toString()),
new Pair<String, CharSequence>("message", response),
new Pair<String, CharSequence>("session_id", mobileSessionId.toString()));
| protected boolean | templatizedFeedHandler(com.facebook.api.FacebookMethod method, java.lang.String titleTemplate, java.lang.String titleData, java.lang.String bodyTemplate, java.lang.String bodyData, java.lang.String bodyGeneral, java.util.Collection pictures, java.lang.String targetIds)
assert (pictures == null || pictures.size() <= 4);
long actorId = this.users_getLoggedInUser();
ArrayList<Pair<String, CharSequence>> params = new ArrayList<Pair<String, CharSequence>>(method.numParams());
//these are always required parameters
params.add(new Pair<String, CharSequence>("actor_id", Long.toString(actorId)));
params.add(new Pair<String, CharSequence>("title_template", titleTemplate));
//these are optional parameters
if (titleData != null) {
params.add(new Pair<String, CharSequence>("title_data", titleData));
}
if (bodyTemplate != null) {
params.add(new Pair<String, CharSequence>("body_template", bodyTemplate));
if (bodyData != null) {
params.add(new Pair<String, CharSequence>("body_data", bodyData));
}
}
if (bodyGeneral != null) {
params.add(new Pair<String, CharSequence>("body_general", bodyGeneral));
}
if (pictures != null) {
int count = 1;
for (IPair picture : pictures) {
params.add(new Pair<String, CharSequence>("image_" + count, picture.getFirst().toString()));
if (picture.getSecond() != null) {
params.add(new Pair<String, CharSequence>("image_" + count + "_link", picture.getSecond().toString()));
}
count++;
}
}
if (targetIds != null) {
params.add(new Pair<String, CharSequence>("target_ids", targetIds));
}
this.callMethod(method, params);
return this.rawResponse.contains(">1<"); //a code of '1' indicates success
| public boolean | users_clearStatus()Clears the logged-in user's Facebook status.
Requires the status_update extended permission.
return extractBoolean(this.callMethod(FacebookMethod.USERS_SET_STATUS,
new Pair<String, CharSequence>("clear", "1")));
| public T | users_getInfo(java.util.Collection userIds, java.util.Set fields)Retrieves the requested info fields for the requested set of users.
// assertions test for invalid params
if (null == userIds) {
throw new IllegalArgumentException("userIds cannot be null");
}
if (fields == null || fields.isEmpty()) {
throw new IllegalArgumentException("fields should not be empty");
}
return this.callMethod(FacebookMethod.USERS_GET_INFO,
new Pair<String, CharSequence>("uids", delimit(userIds)),
new Pair<String, CharSequence>("fields", delimit(fields)));
| public T | users_getInfo(java.util.Collection userIds, java.util.EnumSet fields)Retrieves the requested info fields for the requested set of users.
// assertions test for invalid params
assert (userIds != null);
assert (fields != null);
assert (!fields.isEmpty());
return this.callMethod(FacebookMethod.USERS_GET_INFO,
new Pair<String, CharSequence>("uids", delimit(userIds)),
new Pair<String, CharSequence>("fields", delimit(fields)));
| public long | users_getLoggedInUser()Retrieves the user ID of the user logged in to this API session
T result = this.callMethod(FacebookMethod.USERS_GET_LOGGED_IN_USER);
return extractLong(result);
| public boolean | users_hasAppPermission(java.lang.CharSequence permission)Retrieves whether the logged-in user has granted the specified permission
to this application.
return extractBoolean(this.callMethod(FacebookMethod.USERS_HAS_APP_PERMISSION,
new Pair<String, CharSequence>("ext_perm", permission)));
| public boolean | users_hasAppPermission(com.facebook.api.Permission perm)
return this.users_hasAppPermission(perm.getName());
| public boolean | users_isAppAdded()Retrieves an indicator of whether the logged-in user has installed the
application associated with the _apiKey.
return extractBoolean(this.callMethod(FacebookMethod.USERS_IS_APP_ADDED));
| public boolean | users_setStatus(java.lang.String newStatus, boolean clear)
if (clear) {
this.users_clearStatus();
}
return this.users_setStatus(newStatus);
| public boolean | users_setStatus(java.lang.String status)Sets the logged-in user's Facebook status.
Requires the status_update extended permission.
return extractBoolean(this.callMethod(FacebookMethod.USERS_SET_STATUS,
new Pair<String, CharSequence>("status", status)));
|
|