Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
facebook4j.FacebookImpl Maven / Gradle / Ivy
/*
* Copyright 2012 Ryuji Yamashita
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package facebook4j;
import facebook4j.Question.Option;
import facebook4j.auth.Authorization;
import facebook4j.conf.Configuration;
import facebook4j.internal.http.HttpParameter;
import facebook4j.internal.http.HttpResponse;
import facebook4j.internal.org.json.JSONArray;
import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject;
import facebook4j.internal.util.z_F4JInternalStringUtil;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static facebook4j.internal.util.z_F4JInternalParseUtil.*;
/**
* A java representation of the Facebook Graph API
* This class is thread safe and can be cached/re-used and used concurrently.
* Currently this class is not carefully designed to be extended. It is suggested to extend this class only for mock testing purpose.
*
* @author Ryuji Yamashita - roundrop at gmail.com
*/
class FacebookImpl extends FacebookBaseImpl implements Facebook {
private static final long serialVersionUID = 6277119018105563020L;
/*package*/
FacebookImpl(Configuration conf, Authorization auth) {
super(conf, auth);
}
private String buildEndpoint(String id) {
return buildEndpoint(id, null, null);
}
private String buildEndpoint(String id, Reading reading) {
return buildEndpoint(id, null, reading);
}
private String buildEndpoint(String id, String connection) {
return buildEndpoint(id, connection, null);
}
private String buildEndpoint(String id, String connection, Reading reading) {
StringBuilder url = new StringBuilder()
.append(conf.getRestBaseURL() + id)
.append(connection == null ? "" : "/" + connection)
.append(reading == null ? "" : "?" + reading.getQuery());
return url.toString();
}
private String buildVideoEndpoint(String id, String connection) {
return buildVideoEndpoint(id, connection, null);
}
private String buildVideoEndpoint(String id, String connection, Reading reading) {
StringBuilder url = new StringBuilder()
.append(conf.getVideoBaseURL() + id)
.append(connection == null ? "" : "/" + connection)
.append(reading == null ? "" : "?" + reading.getQuery());
return url.toString();
}
private String buildSearchEndpoint(String query, String objectType, Reading reading) {
String q = null;
if (query != null) {
q = HttpParameter.encode(query);
}
StringBuilder url = new StringBuilder()
.append(buildEndpoint("search"))
.append(objectType == null ? "" : "?type=" + objectType)
.append(q == null ? "" : objectType == null ? "?q=" + q : "&q=" + q)
.append(reading == null ? "" : "&" + reading.getQuery());
return url.toString();
}
/* User Methods */
public User getMe() throws FacebookException {
return getMe(null);
}
public User getMe(Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
User user = factory.createUser(get(buildEndpoint("me", reading)));
return user;
}
public User getUser(String userId) throws FacebookException {
return getUser(userId, null);
}
public User getUser(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
User user = factory.createUser(get(buildEndpoint(userId, reading)));
return user;
}
public URL getPictureURL() throws FacebookException {
ensureAuthorizationEnabled();
return getPictureURL("me");
}
public URL getPictureURL(PictureSize size) throws FacebookException {
ensureAuthorizationEnabled();
return getPictureURL("me", size);
}
public URL getPictureURL(String userId) throws FacebookException {
return getPictureURL(userId, null);
}
public URL getPictureURL(String userId, PictureSize size) throws FacebookException {
return _getPictureURL(userId, size);
}
public URL getSSLPictureURL() throws FacebookException {
ensureAuthorizationEnabled();
return getSSLPictureURL("me");
}
public URL getSSLPictureURL(PictureSize size) throws FacebookException {
ensureAuthorizationEnabled();
return getSSLPictureURL("me", size);
}
public URL getSSLPictureURL(String userId) throws FacebookException {
return getSSLPictureURL(userId, null);
}
public URL getSSLPictureURL(String userId, PictureSize size) throws FacebookException {
return _getSSLPictureURL(userId, size);
}
public List getUsers(String... ids) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createUserArray(get(conf.getRestBaseURL(), new HttpParameter[] {
new HttpParameter("ids", z_F4JInternalStringUtil.join(ids))}));
}
/* Account Methods */
public ResponseList getAccounts() throws FacebookException {
return getAccounts("me", null);
}
public ResponseList getAccounts(Reading reading) throws FacebookException {
return getAccounts("me", reading);
}
public ResponseList getAccounts(String userId) throws FacebookException {
return getAccounts(userId, null);
}
public ResponseList getAccounts(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createAccountList(get(buildEndpoint(userId, "accounts", reading)));
}
/* Achievement Methods */
public ResponseList getAchievements() throws FacebookException {
return getAchievements("me", null);
}
public ResponseList getAchievements(Reading reading) throws FacebookException {
return getAchievements("me", reading);
}
public ResponseList getAchievements(String userId) throws FacebookException {
return getAchievements(userId, null);
}
public ResponseList getAchievements(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createAchievementList(get(buildEndpoint(userId, "achievements", reading)));
}
public String postAchievement(URL achievementURL) throws FacebookException {
return postAchievement("me", achievementURL);
}
public String postAchievement(String userId, URL achievementURL) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(userId, "achievements"),
new HttpParameter[] {new HttpParameter("achievement", achievementURL.toString())}
).asJSONObject();
try {
return json.getString("id");
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}
public boolean deleteAchievement(URL achievementURL) throws FacebookException {
return deleteAchievement("me", achievementURL);
}
public boolean deleteAchievement(String userId, URL achievementURL) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(userId, "achievements"),
new HttpParameter[] {new HttpParameter("achievement", achievementURL.toString())});
return Boolean.valueOf(res.asString().trim());
}
/* Activity Methods */
public ResponseList getActivities() throws FacebookException {
return getActivities("me", null);
}
public ResponseList getActivities(Reading reading) throws FacebookException {
return getActivities("me", reading);
}
public ResponseList getActivities(String userId) throws FacebookException {
return getActivities(userId, null);
}
public ResponseList getActivities(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createActivityList(get(buildEndpoint(userId, "activities", reading)));
}
/* Album Methods */
public ResponseList getAlbums() throws FacebookException {
return getAlbums("me", null);
}
public ResponseList getAlbums(Reading reading) throws FacebookException {
return getAlbums("me", reading);
}
public ResponseList getAlbums(String id) throws FacebookException {
return getAlbums(id, null);
}
public ResponseList getAlbums(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createAlbumList(get(buildEndpoint(id, "albums", reading)));
}
public Album getAlbum(String albumId) throws FacebookException {
return getAlbum(albumId, null);
}
public Album getAlbum(String albumId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createAlbum(get(buildEndpoint(albumId, reading)));
}
public String createAlbum(AlbumUpdate albumUpdate) throws FacebookException {
return createAlbum("me", albumUpdate);
}
public String createAlbum(String userId, AlbumUpdate albumUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(userId, "albums"), albumUpdate.asHttpParameterArray())
.asJSONObject();
try {
return json.getString("id");
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}
public ResponseList getAlbumPhotos(String albumId) throws FacebookException {
return getAlbumPhotos(albumId, null);
}
public ResponseList getAlbumPhotos(String albumId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPhotoList(get(buildEndpoint(albumId, "photos", reading)));
}
public String addAlbumPhoto(String albumId, Media source) throws FacebookException {
return addAlbumPhoto(albumId, source, null);
}
public String addAlbumPhoto(String albumId, Media source, String message) throws FacebookException {
ensureAuthorizationEnabled();
List httpParams = new ArrayList();
httpParams.add(source.asHttpParameter("source"));
if (message != null) {
httpParams.add(new HttpParameter("message", message));
}
JSONObject json = post(buildEndpoint(albumId, "photos"),
httpParams.toArray(new HttpParameter[httpParams.size()]))
.asJSONObject();
try {
return json.getString("id");
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}
public ResponseList getAlbumComments(String albumId) throws FacebookException {
return getAlbumComments(albumId, null);
}
public ResponseList getAlbumComments(String albumId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getComments(albumId, reading);
}
public String commentAlbum(String albumId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _comment(albumId, message);
}
public ResponseList getAlbumLikes(String albumId) throws FacebookException {
return getAlbumLikes(albumId, null);
}
public ResponseList getAlbumLikes(String albumId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLikeList(get(buildEndpoint(albumId, "likes", reading)));
}
public boolean likeAlbum(String albumId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(albumId);
}
public boolean unlikeAlbum(String albumId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(albumId);
}
public URL getAlbumCoverPhoto(String albumId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = get(buildEndpoint(albumId, "picture"));
try {
return new URL(res.getResponseHeader("Location"));
} catch (MalformedURLException urle) {
throw new FacebookException(urle.getMessage(), urle);
}
}
/* Book Methods */
public ResponseList getBooks() throws FacebookException {
return getBooks("me", null);
}
public ResponseList getBooks(Reading reading) throws FacebookException {
return getBooks("me", reading);
}
public ResponseList getBooks(String userId) throws FacebookException {
return getBooks(userId, null);
}
public ResponseList getBooks(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createBookList(get(buildEndpoint(userId, "books", reading)));
}
/* Checkin Methods */
public ResponseList getCheckins() throws FacebookException {
return getCheckins("me", null);
}
public ResponseList getCheckins(Reading reading) throws FacebookException {
return getCheckins("me", reading);
}
public ResponseList getCheckins(String id) throws FacebookException {
return getCheckins(id, null);
}
public ResponseList getCheckins(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createCheckinList(get(buildEndpoint(id, "checkins", reading)));
}
public String checkin(CheckinUpdate checkinUpdate) throws FacebookException {
return checkin("me", checkinUpdate);
}
public String checkin(String userId, CheckinUpdate checkinUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(userId, "checkins"), checkinUpdate.asHttpParameterArray())
.asJSONObject();
return getRawString("id", json);
}
public Checkin getCheckin(String checkinId) throws FacebookException {
return getCheckin(checkinId, null);
}
public Checkin getCheckin(String checkinId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createCheckin(get(buildEndpoint(checkinId, reading)));
}
public ResponseList getCheckinComments(String checkinId) throws FacebookException {
return getCheckinComments(checkinId, null);
}
public ResponseList getCheckinComments(String checkinId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getComments(checkinId, reading);
}
public String commentCheckin(String checkinId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _comment(checkinId, message);
}
public ResponseList getCheckinLikes(String checkinId) throws FacebookException {
return getCheckinLikes(checkinId, null);
}
public ResponseList getCheckinLikes(String checkinId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLikeList(get(buildEndpoint(checkinId, "likes", reading)));
}
public boolean likeCheckin(String checkinId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(checkinId);
}
public boolean unlikeCheckin(String checkinId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(checkinId);
}
/* Domain Methods */
public Domain getDomain(String domainId) throws FacebookException {
return factory.createDomain(get(buildEndpoint(domainId)));
}
public Domain getDomainByName(String domainName) throws FacebookException {
return factory.createDomain(get(conf.getRestBaseURL(),
new HttpParameter[]{new HttpParameter("domain", domainName)}));
}
public List getDomainsByName(String... domainName) throws FacebookException {
String domainNames = z_F4JInternalStringUtil.join(domainName);
return factory.createDomainArray(get(conf.getRestBaseURL(),
new HttpParameter[]{new HttpParameter("domains", domainNames)}));
}
/* Event Methods */
public ResponseList getEvents() throws FacebookException {
return getEvents("me", null);
}
public ResponseList getEvents(Reading reading) throws FacebookException {
return getEvents("me", reading);
}
public ResponseList getEvents(String id) throws FacebookException {
return getEvents(id, null);
}
public ResponseList getEvents(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createEventList(get(buildEndpoint(id, "events", reading)));
}
public String createEvent(EventUpdate eventUpdate) throws FacebookException {
return createEvent("me", eventUpdate);
}
public String createEvent(String id, EventUpdate eventUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(id, "events"), eventUpdate.asHttpParameterArray())
.asJSONObject();
return getRawString("id", json);
}
public Event getEvent(String eventId) throws FacebookException {
return getEvent(eventId, null);
}
public Event getEvent(String eventId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = get(buildEndpoint(eventId, reading));
String resStr = res.asString().trim();
if (resStr.equals("false")) {
return null;
}
return factory.createEvent(res);
}
public boolean editEvent(String eventId, EventUpdate eventUpdate) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId), eventUpdate.asHttpParameterArray());
return Boolean.valueOf(res.asString().trim());
}
public boolean deleteEvent(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(eventId));
return Boolean.valueOf(res.asString().trim());
}
public String postEventLink(String eventId, URL link) throws FacebookException {
return postEventLink(eventId, link, null);
}
public String postEventLink(String eventId, URL link, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _postLink(eventId, link, message);
}
public String postEventStatusMessage(String eventId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _postStatusMessage(eventId, message);
}
public ResponseList getRSVPStatusAsNoreply(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "noreply")));
}
public ResponseList getRSVPStatusAsNoreply(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "noreply/" + userId)));
}
public ResponseList getRSVPStatusAsInvited(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "invited")));
}
public ResponseList getRSVPStatusAsInvited(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "invited/" + userId)));
}
public boolean inviteToEvent(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId, "invited/" + userId));
return Boolean.valueOf(res.asString().trim());
}
public boolean inviteToEvent(String eventId, String[] userIds) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId, "invited"), new HttpParameter[] {
new HttpParameter("users", z_F4JInternalStringUtil.join(userIds))});
return Boolean.valueOf(res.asString().trim());
}
public boolean uninviteFromEvent(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(eventId, "invited/" + userId));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getRSVPStatusInAttending(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "attending")));
}
public ResponseList getRSVPStatusInAttending(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "attending/" + userId)));
}
public boolean rsvpEventAsAttending(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId, "attending"));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getRSVPStatusInMaybe(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "maybe")));
}
public ResponseList getRSVPStatusInMaybe(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "maybe/" + userId)));
}
public boolean rsvpEventAsMaybe(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId, "maybe"));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getRSVPStatusInDeclined(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "declined")));
}
public ResponseList getRSVPStatusInDeclined(String eventId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createRSVPStatusList(get(buildEndpoint(eventId, "declined/" + userId)));
}
public boolean rsvpEventAsDeclined(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId, "declined"));
return Boolean.valueOf(res.asString().trim());
}
public URL getEventPictureURL(String eventId) throws FacebookException {
return getEventPictureURL(eventId, null);
}
public URL getEventPictureURL(String eventId, PictureSize size) throws FacebookException {
ensureAuthorizationEnabled();
return _getPictureURL(eventId, size);
}
public boolean updateEventPicture(String eventId, Media source) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(eventId, "picture"),
new HttpParameter[] {source.asHttpParameter("source")});
return Boolean.valueOf(res.asString().trim());
}
public boolean deleteEventPicture(String eventId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(eventId, "picture"));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getEventPhotos(String eventId) throws FacebookException {
return getEventPhotos(eventId, null);
}
public ResponseList getEventPhotos(String eventId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPhotoList(get(buildEndpoint(eventId, "photos", reading)));
}
public String postEventPhoto(String eventId, Media source) throws FacebookException {
return postEventPhoto(eventId, source, null);
}
public String postEventPhoto(String eventId, Media source, String message) throws FacebookException {
ensureAuthorizationEnabled();
HttpParameter[] httpParameters = new HttpParameter[] {source.asHttpParameter("source")};
if (message != null) {
httpParameters = HttpParameter.merge(httpParameters,
new HttpParameter[]{new HttpParameter("message", message)});
}
JSONObject json = post(buildEndpoint(eventId, "photos"), httpParameters).asJSONObject();
return getRawString("id", json);
}
public ResponseList getEventVideos(String eventId) throws FacebookException {
return getEventVideos(eventId, null);
}
public ResponseList getEventVideos(String eventId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createVideoList(get(buildEndpoint(eventId, "videos", reading)));
}
public String postEventVideo(String eventId, Media source) throws FacebookException {
return postEventVideo(eventId, source, null, null);
}
public String postEventVideo(String eventId, Media source, String title, String description) throws FacebookException {
ensureAuthorizationEnabled();
HttpParameter[] httpParameters = new HttpParameter[] {source.asHttpParameter("source")};
if (title != null) {
httpParameters = HttpParameter.merge(httpParameters,
new HttpParameter[]{new HttpParameter("title", title)});
}
if (description != null) {
httpParameters = HttpParameter.merge(httpParameters,
new HttpParameter[]{new HttpParameter("description", description)});
}
JSONObject json = post(buildVideoEndpoint(eventId, "videos"), httpParameters).asJSONObject();
return getRawString("id", json);
}
/* Family Methods */
public ResponseList getFamily() throws FacebookException {
return getFamily("me", null);
}
public ResponseList getFamily(Reading reading) throws FacebookException {
return getFamily("me", reading);
}
public ResponseList getFamily(String userId) throws FacebookException {
return getFamily(userId, null);
}
public ResponseList getFamily(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFamilyList(get(buildEndpoint(userId, "family", reading)));
}
/* Post Methods */
public ResponseList getFeed() throws FacebookException {
return getFeed("me", null);
}
public ResponseList getFeed(Reading reading) throws FacebookException {
return getFeed("me", reading);
}
public ResponseList getFeed(String id) throws FacebookException {
return getFeed(id, null);
}
public ResponseList getFeed(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint(id, "feed", reading)));
}
public ResponseList getHome() throws FacebookException {
return getHome(null);
}
public ResponseList getHome(Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint("me", "home", reading)));
}
public ResponseList getPosts() throws FacebookException {
return getPosts("me", null);
}
public ResponseList getPosts(Reading reading) throws FacebookException {
return getPosts("me", reading);
}
public ResponseList getPosts(String id) throws FacebookException {
return getPosts(id, null);
}
public ResponseList getPosts(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint(id, "posts", reading)));
}
public ResponseList getStatuses() throws FacebookException {
return getStatuses("me", null);
}
public ResponseList getStatuses(Reading reading) throws FacebookException {
return getStatuses("me", reading);
}
public ResponseList getStatuses(String id) throws FacebookException {
return getStatuses(id, null);
}
public ResponseList getStatuses(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint(id, "statuses", reading)));
}
public Post getPost(String postId) throws FacebookException {
return getPost(postId, null);
}
public Post getPost(String postId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPost(get(buildEndpoint(postId, reading)));
}
public boolean deletePost(String postId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(postId));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getPostComments(String postId) throws FacebookException {
return getPostComments(postId, null);
}
public ResponseList getPostComments(String postId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getComments(postId, reading);
}
public String commentPost(String postId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _comment(postId, message);
}
public ResponseList getPostLikes(String postId) throws FacebookException {
return getPostLikes(postId, null);
}
public ResponseList getPostLikes(String postId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLikeList(get(buildEndpoint(postId, "likes", reading)));
}
public boolean likePost(String postId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(postId);
}
public boolean unlikePost(String postId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(postId);
}
public ResponseList getPostInsights(String postId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createInsightList(get(buildEndpoint(postId, "insights")));
}
public String postFeed(PostUpdate postUpdate) throws FacebookException {
return postFeed("me", postUpdate);
}
public String postFeed(String id, PostUpdate postUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(id, "feed"), postUpdate.asHttpParameterArray())
.asJSONObject();
return getRawString("id", json);
}
public String postStatusMessage(String message) throws FacebookException {
return postStatusMessage("me", message);
}
public String postStatusMessage(String id, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _postStatusMessage(id, message);
}
public ResponseList getTagged() throws FacebookException {
return getTagged("me", null);
}
public ResponseList getTagged(Reading reading) throws FacebookException {
return getTagged("me", reading);
}
public ResponseList getTagged(String userId) throws FacebookException {
return getTagged(userId, null);
}
public ResponseList getTagged(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint(userId, "tagged", reading)));
}
/* Friend Methods */
public ResponseList getFriendlists() throws FacebookException {
return getFriendlists("me", null);
}
public ResponseList getFriendlists(Reading reading) throws FacebookException {
return getFriendlists("me", reading);
}
public ResponseList getFriendlists(String userId) throws FacebookException {
return getFriendlists(userId, null);
}
public ResponseList getFriendlists(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendlistList(get(buildEndpoint(userId, "friendlists", reading)));
}
public ResponseList getFriendRequests() throws FacebookException {
return getFriendRequests("me", null);
}
public ResponseList getFriendRequests(Reading reading) throws FacebookException {
return getFriendRequests("me", reading);
}
public ResponseList getFriendRequests(String userId) throws FacebookException {
return getFriendRequests(userId, null);
}
public ResponseList getFriendRequests(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendRequestList(get(buildEndpoint(userId, "friendrequests", reading)));
}
public ResponseList getFriends() throws FacebookException {
return getFriends("me", null);
}
public ResponseList getFriends(Reading reading) throws FacebookException {
return getFriends("me", reading);
}
public ResponseList getFriends(String userId) throws FacebookException {
return getFriends(userId, null);
}
public ResponseList getFriends(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendList(get(buildEndpoint(userId, "friends", reading)));
}
public ResponseList getMutualFriends(String friendUserId) throws FacebookException {
return getMutualFriends("me", friendUserId, null);
}
public ResponseList getMutualFriends(String friendUserId, Reading reading) throws FacebookException {
return getMutualFriends("me", friendUserId, reading);
}
public ResponseList getMutualFriends(String userId1, String userId2) throws FacebookException {
return getMutualFriends(userId1, userId2, null);
}
public ResponseList getMutualFriends(String userId1, String userId2, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendList(get(buildEndpoint(userId1, "mutualfriends/" + userId2, reading)));
}
public String createFriendlist(String friendlistName) throws FacebookException {
return createFriendlist("me", friendlistName);
}
public String createFriendlist(String userId, String friendlistName) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(userId, "friendlists"),
new HttpParameter[]{
new HttpParameter("name", friendlistName)
})
.asJSONObject();
return getRawString("id", json);
}
public boolean deleteFriendlist(String friendlistId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(friendlistId));
return Boolean.valueOf(res.asString().trim());
}
public boolean addFriendlistMember(String friendlistId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(friendlistId + "/members/" + userId));
return Boolean.valueOf(res.asString().trim());
}
public boolean removeFriendlistMember(String friendlistId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(friendlistId + "/members/" + userId));
return Boolean.valueOf(res.asString().trim());
}
public Friendlist getFriendlist(String friendlistId) throws FacebookException {
return getFriendlist(friendlistId, null);
}
public Friendlist getFriendlist(String friendlistId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendlist(get(buildEndpoint(friendlistId, reading)));
}
public ResponseList getFriendlistMembers(String friendlistId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendList(get(buildEndpoint(friendlistId + "/members")));
}
public ResponseList getBelongsFriend(String friendId) throws FacebookException {
return getBelongsFriend("me", friendId);
}
public ResponseList getBelongsFriend(String friendId, Reading reading) throws FacebookException {
return getBelongsFriend("me", friendId, reading);
}
public ResponseList getBelongsFriend(String userId, String friendId) throws FacebookException {
return getBelongsFriend(userId, friendId, null);
}
public ResponseList getBelongsFriend(String userId, String friendId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createFriendList(get(buildEndpoint(userId, "friends/" + friendId, reading)));
}
/* Favorite Methods */
public ResponseList getGames() throws FacebookException {
return getGames("me", null);
}
public ResponseList getGames(Reading reading) throws FacebookException {
return getGames("me", reading);
}
public ResponseList getGames(String userId) throws FacebookException {
return getGames(userId, null);
}
public ResponseList getGames(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createGameList(get(buildEndpoint(userId, "games", reading)));
}
public ResponseList getMovies() throws FacebookException {
return getMovies("me", null);
}
public ResponseList getMovies(Reading reading) throws FacebookException {
return getMovies("me", reading);
}
public ResponseList getMovies(String userId) throws FacebookException {
return getMovies(userId, null);
}
public ResponseList getMovies(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createMovieList(get(buildEndpoint(userId, "movies", reading)));
}
public ResponseList getMusic() throws FacebookException {
return getMusic("me", null);
}
public ResponseList getMusic(Reading reading) throws FacebookException {
return getMusic("me", reading);
}
public ResponseList getMusic(String userId) throws FacebookException {
return getMusic(userId, null);
}
public ResponseList getMusic(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createMusicList(get(buildEndpoint(userId, "music", reading)));
}
public ResponseList getTelevision() throws FacebookException {
return getTelevision("me", null);
}
public ResponseList getTelevision(Reading reading) throws FacebookException {
return getTelevision("me", reading);
}
public ResponseList getTelevision(String userId) throws FacebookException {
return getTelevision(userId, null);
}
public ResponseList getTelevision(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createTelevisionList(get(buildEndpoint(userId, "television", reading)));
}
public ResponseList getInterests() throws FacebookException {
return getInterests("me", null);
}
public ResponseList getInterests(Reading reading) throws FacebookException {
return getInterests("me", reading);
}
public ResponseList getInterests(String userId) throws FacebookException {
return getInterests(userId, null);
}
public ResponseList getInterests(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createInterestList(get(buildEndpoint(userId, "interests", reading)));
}
/* Group Methods */
public ResponseList getGroups() throws FacebookException {
return getGroups("me", null);
}
public ResponseList getGroups(Reading reading) throws FacebookException {
return getGroups("me", reading);
}
public ResponseList getGroups(String userId) throws FacebookException {
return getGroups(userId, null);
}
public ResponseList getGroups(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createGroupList(get(buildEndpoint(userId, "groups", reading)));
}
public Group getGroup(String groupId) throws FacebookException {
return getGroup(groupId, null);
}
public Group getGroup(String groupId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createGroup(get(buildEndpoint(groupId, reading)));
}
public ResponseList getGroupFeed(String groupId) throws FacebookException {
return getGroupFeed(groupId, null);
}
public ResponseList getGroupFeed(String groupId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint(groupId, "feed", reading)));
}
public ResponseList getGroupMembers(String groupId) throws FacebookException {
return getGroupMembers(groupId, null);
}
public ResponseList getGroupMembers(String groupId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createGroupMemberList(get(buildEndpoint(groupId, "members", reading)));
}
public URL getGroupPictureURL(String groupId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = get(buildEndpoint(groupId, "picture"));
try {
return new URL(res.getResponseHeader("Location"));
} catch (MalformedURLException urle) {
throw new FacebookException(urle.getMessage(), urle);
}
}
public ResponseList getGroupDocs(String groupId) throws FacebookException {
return getGroupDocs(groupId, null);
}
public ResponseList getGroupDocs(String groupId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createGroupDocList(get(buildEndpoint(groupId, "docs", reading)));
}
public String postGroupLink(String groupId, URL linkURL) throws FacebookException {
return postGroupLink(groupId, linkURL, null);
}
public String postGroupLink(String groupId, URL linkURL, String message) throws FacebookException {
ensureAuthorizationEnabled();
HttpParameter[] httpParameters = new HttpParameter[]{new HttpParameter("link", linkURL.toString())};
if (message != null) {
httpParameters = HttpParameter.merge(httpParameters,
new HttpParameter[] {new HttpParameter("message", message)});
}
JSONObject json = post(buildEndpoint(groupId, "feed"), httpParameters).asJSONObject();
return getRawString("id", json);
}
public String postGroupFeed(String groupId, PostUpdate postUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(groupId, "feed"),
postUpdate.asHttpParameterArray()
).asJSONObject();
return getRawString("id", json);
}
public String postGroupStatusMessage(String groupId, String message) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(groupId, "feed"), new HttpParameter[]{
new HttpParameter("message", message)
}).asJSONObject();
return getRawString("id", json);
}
/* Message Methods */
public InboxResponseList getInbox() throws FacebookException {
return getInbox("me", null);
}
public InboxResponseList getInbox(Reading reading) throws FacebookException {
return getInbox("me", reading);
}
public InboxResponseList getInbox(String userId) throws FacebookException {
return getInbox(userId, null);
}
public InboxResponseList getInbox(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createInboxList(get(buildEndpoint(userId, "inbox", reading)));
}
public ResponseList getOutbox() throws FacebookException {
return getOutbox("me", null);
}
public ResponseList getOutbox(Reading reading) throws FacebookException {
return getOutbox("me", reading);
}
public ResponseList getOutbox(String userId) throws FacebookException {
return getOutbox(userId, null);
}
public ResponseList getOutbox(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createMessageList(get(buildEndpoint(userId, "outbox", reading)));
}
public ResponseList getUpdates() throws FacebookException {
return getUpdates("me", null);
}
public ResponseList getUpdates(Reading reading) throws FacebookException {
return getUpdates("me", reading);
}
public ResponseList getUpdates(String userId) throws FacebookException {
return getUpdates(userId, null);
}
public ResponseList getUpdates(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createMessageList(get(buildEndpoint(userId, "updates", reading)));
}
public Message getMessage(String messageId) throws FacebookException {
return getMessage(messageId, null);
}
public Message getMessage(String messageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createMessage(get(buildEndpoint(messageId, reading)));
}
/* Like Methods */
public ResponseList getUserLikes() throws FacebookException {
return _getLikes("me", null);
}
public ResponseList getUserLikes(Reading reading) throws FacebookException {
return _getLikes("me", reading);
}
public ResponseList getUserLikes(String userId) throws FacebookException {
return _getLikes(userId, null);
}
public ResponseList getUserLikes(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLikeList(get(buildEndpoint(userId, "likes", reading)));
}
/* Comment Methods */
public Comment getComment(String commentId) throws FacebookException {
return factory.createComment(get(buildEndpoint(commentId)));
}
public boolean deleteComment(String commentId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(commentId));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getCommentLikes(String commentId) throws FacebookException {
return getCommentLikes(commentId, null);
}
public ResponseList getCommentLikes(String commentId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLikeList(get(buildEndpoint(commentId, "likes", reading)));
}
public boolean likeComment(String commentId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(commentId);
}
public boolean unlikeComment(String commentId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(commentId);
}
/* Link Methods */
public ResponseList getLinks() throws FacebookException {
return getLinks("me", null);
}
public ResponseList getLinks(Reading reading) throws FacebookException {
return getLinks("me", reading);
}
public ResponseList getLinks(String id) throws FacebookException {
return getLinks(id, null);
}
public ResponseList getLinks(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLinkList(get(buildEndpoint(id, "links", reading)));
}
public Link getLink(String linkId) throws FacebookException {
return getLink(linkId, null);
}
public Link getLink(String linkId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLink(get(buildEndpoint(linkId, reading)));
}
public ResponseList getLinkComments(String linkId) throws FacebookException {
return getLinkComments(linkId, null);
}
public ResponseList getLinkComments(String linkId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getComments(linkId, reading);
}
public String commentLink(String linkId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _comment(linkId, message);
}
public ResponseList getLinkLikes(String linkId) throws FacebookException {
return getLinkLikes(linkId, null);
}
public ResponseList getLinkLikes(String linkId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getLikes(linkId, reading);
}
public boolean likeLink(String linkId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(linkId);
}
public boolean unlikeLink(String linkId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(linkId);
}
public String postLink(URL link) throws FacebookException {
ensureAuthorizationEnabled();
return _postLink("me", link, null);
}
public String postLink(URL link, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _postLink("me", link, message);
}
public String postLink(String userId, URL link) throws FacebookException {
ensureAuthorizationEnabled();
return _postLink(userId, link, null);
}
public String postLink(String userId, URL link, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _postLink(userId, link, message);
}
/* Location Methods */
public ResponseList getLocations() throws FacebookException {
return getLocations("me", null);
}
public ResponseList getLocations(Reading reading) throws FacebookException {
return getLocations("me", reading);
}
public ResponseList getLocations(String userId) throws FacebookException {
return getLocations(userId, null);
}
public ResponseList getLocations(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLocationList(get(buildEndpoint(userId, "locations", reading)));
}
/* Note Methods */
public ResponseList getNotes() throws FacebookException {
return getNotes("me", null);
}
public ResponseList getNotes(Reading reading) throws FacebookException {
return getNotes("me", reading);
}
public ResponseList getNotes(String id) throws FacebookException {
return getNotes(id, null);
}
public ResponseList getNotes(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createNoteList(get(buildEndpoint(id, "notes", reading)));
}
public String createNote(String subject, String message) throws FacebookException {
return createNote("me", subject, message);
}
public String createNote(String id, String subject, String message) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(id, "notes"), new HttpParameter[] {
new HttpParameter("subject", subject),
new HttpParameter("message", message)
}).asJSONObject();
try {
return json.getString("id");
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}
public Note getNote(String noteId) throws FacebookException {
return getNote(noteId, null);
}
public Note getNote(String noteId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createNote(get(buildEndpoint(noteId, reading)));
}
public ResponseList getNoteComments(String noteId) throws FacebookException {
return getNoteComments(noteId, null);
}
public ResponseList getNoteComments(String noteId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getComments(noteId, reading);
}
public String commentNote(String noteId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _comment(noteId, message);
}
public ResponseList getNoteLikes(String noteId) throws FacebookException {
return getNoteLikes(noteId, null);
}
public ResponseList getNoteLikes(String noteId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getLikes(noteId, reading);
}
public boolean likeNote(String noteId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(noteId);
}
public boolean unlikeNote(String noteId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(noteId);
}
/* Notification Methods */
public ResponseList getNotifications() throws FacebookException {
return getNotifications("me", null);
}
public ResponseList getNotifications(boolean includeRead) throws FacebookException {
return getNotifications("me", null, includeRead);
}
public ResponseList getNotifications(Reading reading) throws FacebookException {
return getNotifications("me", reading);
}
public ResponseList getNotifications(Reading reading, boolean includeRead) throws FacebookException {
return getNotifications("me", reading, includeRead);
}
public ResponseList getNotifications(String userId) throws FacebookException {
return getNotifications(userId, null);
}
public ResponseList getNotifications(String userId, boolean includeRead) throws FacebookException {
return getNotifications(userId, null, includeRead);
}
public ResponseList getNotifications(String userId, Reading reading) throws FacebookException {
return getNotifications(userId, reading, false);
}
public ResponseList getNotifications(String userId, Reading reading, boolean includeRead) throws FacebookException {
ensureAuthorizationEnabled();
String url = buildEndpoint(userId, "notifications", reading);
HttpResponse res;
if (includeRead) {
res = get(url, new HttpParameter[]{new HttpParameter("include_read", 1)});
} else {
res = get(url);
}
return factory.createNotificationList(res);
}
public boolean markNotificationAsRead(String notificationId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(notificationId), new HttpParameter[] {new HttpParameter("unread", 0)});
return Boolean.valueOf(res.asString().trim());
}
/* Page Methods */
public Page getPage() throws FacebookException {
return getPage("me", null);
}
public Page getPage(Reading reading) throws FacebookException {
return getPage("me", reading);
}
public Page getPage(String pageId) throws FacebookException {
return getPage(pageId, null);
}
public Page getPage(String pageId, Reading reading) throws FacebookException {
HttpResponse res = get(buildEndpoint(pageId, reading));
return factory.createPage(res);
}
public URL getPagePictureURL() throws FacebookException {
return getPagePictureURL("me", null);
}
public URL getPagePictureURL(PictureSize size) throws FacebookException {
return getPagePictureURL("me", size);
}
public URL getPagePictureURL(String pageId) throws FacebookException {
return getPagePictureURL(pageId, null);
}
public URL getPagePictureURL(String pageId, PictureSize size) throws FacebookException {
return _getPictureURL(pageId, size);
}
public ResponseList getPromotablePosts() throws FacebookException {
return getPromotablePosts("me", null);
}
public ResponseList getPromotablePosts(Reading reading) throws FacebookException {
return getPromotablePosts("me", reading);
}
public ResponseList getPromotablePosts(String pageId) throws FacebookException {
return getPromotablePosts(pageId, null);
}
public ResponseList getPromotablePosts(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPostList(get(buildEndpoint(pageId, "promotable_posts", reading)));
}
public boolean updatePageBasicAttributes(PageUpdate pageUpdate) throws FacebookException {
return updatePageBasicAttributes("me", pageUpdate);
}
public boolean updatePageBasicAttributes(String pageId, PageUpdate pageUpdate) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(pageId), pageUpdate.asHttpParameterArray());
return Boolean.valueOf(res.asString().trim());
}
public boolean updatePageProfilePhoto(URL picture) throws FacebookException {
return updatePageProfilePhoto("me", picture);
}
public boolean updatePageProfilePhoto(String pageId, URL picture) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(pageId, "picture"), new HttpParameter[]{new HttpParameter("picture", picture.toString())});
return Boolean.valueOf(res.asString().trim());
}
public boolean updatePageProfilePhoto(Media source) throws FacebookException {
return updatePageProfilePhoto("me", source);
}
public boolean updatePageProfilePhoto(String pageId, Media source) throws FacebookException {
ensureAuthorizationEnabled();
List httpParams = new ArrayList();
httpParams.add(source.asHttpParameter("source"));
HttpResponse res = post(buildEndpoint(pageId, "picture"), httpParams.toArray(new HttpParameter[httpParams.size()]));
return Boolean.valueOf(res.asString().trim());
}
public boolean updatePageCoverPhoto(PageCoverUpdate pageCoverUpdate) throws FacebookException {
return updatePageCoverPhoto("me", pageCoverUpdate);
}
public boolean updatePageCoverPhoto(String pageId, PageCoverUpdate pageCoverUpdate) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(pageId), pageCoverUpdate.asHttpParameterArray());
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getPageSettings() throws FacebookException {
return getPageSettings("me");
}
public ResponseList getPageSettings(String pageId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = get(buildEndpoint(pageId, "settings"));
return factory.createPageSettingList(res);
}
public boolean updatePageSetting(PageSettingUpdate pageSettingUpdate) throws FacebookException {
return updatePageSetting("me", pageSettingUpdate);
}
public boolean updatePageSetting(String pageId, PageSettingUpdate pageSettingUpdate) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(pageId, "settings"), pageSettingUpdate.asHttpParameterArray());
return Boolean.valueOf(res.asString().trim());
}
public String postBackdatingFeed(BackdatingPostUpdate backdatingPostUpdate) throws FacebookException {
return postBackdatingFeed("me", backdatingPostUpdate);
}
public String postBackdatingFeed(String pageId, BackdatingPostUpdate backdatingPostUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(pageId, "feed"), backdatingPostUpdate.asHttpParameterArray())
.asJSONObject();
return getRawString("id", json);
}
public String postPagePhoto(PagePhotoUpdate pagePhotoUpdate) throws FacebookException {
return postPagePhoto("me", pagePhotoUpdate);
}
public String postPagePhoto(String pageId, PagePhotoUpdate pagePhotoUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(pageId, "photos"), pagePhotoUpdate.asHttpParameterArray()).asJSONObject();
try {
return json.getString("id");
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}
public ResponseList getGlobalBrandChildren(String pageId) throws FacebookException {
return getGlobalBrandChildren(pageId, null);
}
public ResponseList getGlobalBrandChildren(String pageId, Reading reading) throws FacebookException {
HttpResponse res = get(buildEndpoint(pageId, "global_brand_children", reading));
return factory.createPageList(res);
}
public ResponseList getPageInsights(String pageId) throws FacebookException {
return getPageInsights(pageId, null);
}
public ResponseList getPageInsights(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createInsightList(get(buildEndpoint(pageId, "insights", reading)));
}
public ResponseList getPageTagged(String pageId) throws FacebookException {
return getPageTagged(pageId, null);
}
public ResponseList getPageTagged(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createTaggedList(get(buildEndpoint(pageId, "tagged", reading)));
}
public ResponseList getMilestones() throws FacebookException {
return getMilestones("me", null);
}
public ResponseList getMilestones(Reading reading) throws FacebookException {
return getMilestones("me", reading);
}
public ResponseList getMilestones(String pageId) throws FacebookException {
return getMilestones(pageId, null);
}
public ResponseList getMilestones(String pageId, Reading reading) throws FacebookException {
return factory.createMilestoneList(get(buildEndpoint(pageId, "milestones", reading)));
}
public String createMilestone(MilestoneUpdate milestoneUpdate) throws FacebookException {
return createMilestone("me", milestoneUpdate);
}
public String createMilestone(String pageId, MilestoneUpdate milestoneUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(pageId, "milestones"), milestoneUpdate.asHttpParameterArray())
.asJSONObject();
return getRawString("id", json);
}
public boolean deleteMilestone(String milestoneId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(milestoneId));
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getPageAdmins() throws FacebookException {
return getPageAdmins("me", null);
}
public ResponseList getPageAdmins(Reading reading) throws FacebookException {
return getPageAdmins("me", reading);
}
public ResponseList getPageAdmins(String pageId) throws FacebookException {
return getPageAdmins(pageId, null);
}
public ResponseList getPageAdmins(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createAdminList(get(buildEndpoint(pageId, "admins", reading)));
}
public ResponseList getTabs() throws FacebookException {
return getTabs("me", null);
}
public ResponseList getTabs(Reading reading) throws FacebookException {
return getTabs("me", reading);
}
public ResponseList getTabs(String pageId) throws FacebookException {
return getTabs(pageId, null);
}
public ResponseList getTabs(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createTabList(get(buildEndpoint(pageId, "tabs", reading)));
}
public ResponseList getInstalledTabs(List appIds) throws FacebookException {
return getInstalledTabs("me", appIds, null);
}
public ResponseList getInstalledTabs(List appIds, Reading reading) throws FacebookException {
return getInstalledTabs("me", appIds, reading);
}
public ResponseList getInstalledTabs(String pageId, List appIds) throws FacebookException {
return getInstalledTabs(pageId, appIds, null);
}
public ResponseList getInstalledTabs(String pageId, List appIds, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
String _appIds = z_F4JInternalStringUtil.join(appIds.toArray(new String[appIds.size()]), ",");
return factory.createTabList(get(buildEndpoint(pageId, "tabs/" + _appIds, reading)));
}
public boolean installTab(String appId) throws FacebookException {
return installTab("me", appId);
}
public boolean installTab(String pageId, String appId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(pageId, "tabs"), new HttpParameter[]{new HttpParameter("app_id", appId)});
return Boolean.valueOf(res.asString().trim());
}
public boolean updateTab(String tabId, TabUpdate tabUpdate) throws FacebookException {
return updateTab("me", tabId, tabUpdate);
}
public boolean updateTab(String pageId, String tabId, TabUpdate tabUpdate) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(pageId, "tabs/" + tabId), tabUpdate.asHttpParameterArray());
return Boolean.valueOf(res.asString().trim());
}
public boolean deleteTab(String tabId) throws FacebookException {
return deleteTab("me", tabId);
}
public boolean deleteTab(String pageId, String tabId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(pageId, "tabs/" + tabId));
return Boolean.valueOf(res.asString().trim());
}
public boolean displayPagePost(String postId, boolean isHidden) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(postId), new HttpParameter[]{new HttpParameter("is_hidden", isHidden)});
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getBlocked() throws FacebookException {
return getBlocked("me", null);
}
public ResponseList getBlocked(Reading reading) throws FacebookException {
return getBlocked("me", reading);
}
public ResponseList getBlocked(String pageId) throws FacebookException {
return getBlocked(pageId, null);
}
public ResponseList getBlocked(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createUserList(get(buildEndpoint(pageId, "blocked", reading)));
}
public Map block(List userIds) throws FacebookException {
return block("me", userIds);
}
public Map block(String pageId, List userIds) throws FacebookException {
ensureAuthorizationEnabled();
String _userIds = z_F4JInternalStringUtil.join(userIds.toArray(new String[userIds.size()]), ",");
HttpResponse res = post(buildEndpoint(pageId, "blocked"), new HttpParameter[]{new HttpParameter("uid", _userIds)});
Map blocks = new HashMap();
JSONObject jsonObject = res.asJSONObject();
Iterator uids = jsonObject.keys();
while (uids.hasNext()) {
String uid = uids.next();
boolean result = getBoolean(uid, jsonObject);
blocks.put(uid, result);
}
return blocks;
}
public boolean unblock(String userId) throws FacebookException {
return unblock("me", userId);
}
public boolean unblock(String pageId, String userId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(pageId, "blocked"), new HttpParameter[]{new HttpParameter("uid", userId)});
return Boolean.valueOf(res.asString().trim());
}
public ResponseList getOffers() throws FacebookException {
return getOffers("me", null);
}
public ResponseList getOffers(Reading reading) throws FacebookException {
return getOffers("me", reading);
}
public ResponseList getOffers(String pageId) throws FacebookException {
return getOffers(pageId, null);
}
public ResponseList getOffers(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createOfferList(get(buildEndpoint(pageId, "offers", reading)));
}
public String createOffer(OfferUpdate offerUpdate) throws FacebookException {
return createOffer("me", offerUpdate);
}
public String createOffer(String pageId, OfferUpdate offerUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(pageId, "offers"), offerUpdate.asHttpParameterArray())
.asJSONObject();
return getRawString("id", json);
}
public boolean deleteOffer(String offerId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(offerId));
return Boolean.valueOf(res.asString().trim());
}
public Offer getOffer(String offerId) throws FacebookException {
return factory.createOffer(get(buildEndpoint(offerId)));
}
public Page getLikedPage(String pageId) throws FacebookException {
return getLikedPage("me", pageId, null);
}
public Page getLikedPage(String pageId, Reading reading) throws FacebookException {
return getLikedPage("me", pageId, reading);
}
public Page getLikedPage(String userId, String pageId) throws FacebookException {
return getLikedPage(userId, pageId, null);
}
public Page getLikedPage(String userId, String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = get(buildEndpoint(userId, "likes/" + pageId, reading));
ResponseList list = factory.createPageList(res);
return list.size() == 0 ? null : list.get(0);
}
/* Permission Methods */
public List getPermissions() throws FacebookException {
return getPermissions("me");
}
public List getPermissions(String userId) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPermissions(get(buildEndpoint(userId, "permissions")));
}
public boolean revokePermission(String permissionName) throws FacebookException {
return revokePermission("me", permissionName);
}
public boolean revokePermission(String userId, String permissionName) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(userId, "permissions/" + permissionName));
return Boolean.valueOf(res.asString().trim());
}
/* Photo Methods */
public ResponseList getUploadedPhotos() throws FacebookException {
return getUploadedPhotos("me", null);
}
public ResponseList getUploadedPhotos(Reading reading) throws FacebookException {
return getUploadedPhotos("me", reading);
}
public ResponseList getUploadedPhotos(String id) throws FacebookException {
return getUploadedPhotos(id, null);
}
public ResponseList getUploadedPhotos(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPhotoList(get(buildEndpoint(id, "photos/uploaded", reading)));
}
public ResponseList getPhotos() throws FacebookException {
return getPhotos("me", null);
}
public ResponseList getPhotos(Reading reading) throws FacebookException {
return getPhotos("me", reading);
}
public ResponseList getPhotos(String id) throws FacebookException {
return getPhotos(id, null);
}
public ResponseList getPhotos(String id, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPhotoList(get(buildEndpoint(id, "photos", reading)));
}
public Photo getPhoto(String photoId) throws FacebookException {
return getPhoto(photoId, null);
}
public Photo getPhoto(String photoId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPhoto(get(buildEndpoint(photoId, reading)));
}
public ResponseList getPhotoComments(String photoId) throws FacebookException {
return getPhotoComments(photoId, null);
}
public ResponseList getPhotoComments(String photoId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getComments(photoId, reading);
}
public String commentPhoto(String photoId, String message) throws FacebookException {
ensureAuthorizationEnabled();
return _comment(photoId, message);
}
public ResponseList getPhotoLikes(String photoId) throws FacebookException {
return getPhotoLikes(photoId, null);
}
public ResponseList getPhotoLikes(String photoId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return _getLikes(photoId, reading);
}
public boolean likePhoto(String photoId) throws FacebookException {
ensureAuthorizationEnabled();
return _like(photoId);
}
public boolean unlikePhoto(String photoId) throws FacebookException {
ensureAuthorizationEnabled();
return _unlike(photoId);
}
public URL getPhotoURL(String photoId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = get(buildEndpoint(photoId, "picture"));
try {
return new URL(res.getResponseHeader("Location"));
} catch (MalformedURLException urle) {
throw new FacebookException(urle.getMessage(), urle);
}
}
public ResponseList getTagsOnPhoto(String photoId) throws FacebookException {
return getTagsOnPhoto(photoId, null);
}
public ResponseList getTagsOnPhoto(String photoId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createTagList(get(buildEndpoint(photoId, "tags", reading)));
}
public boolean addTagToPhoto(String photoId, String toUserId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(photoId, "tags"), new HttpParameter[]{new HttpParameter("to", toUserId)});
return Boolean.valueOf(res.asString().trim());
}
public boolean addTagToPhoto(String photoId, TagUpdate tagUpdate) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = post(buildEndpoint(photoId, "tags"), tagUpdate.asHttpParameterArray());
return Boolean.valueOf(res.asString().trim());
}
public boolean addTagToPhoto(String photoId, List toUserIds) throws FacebookException {
ensureAuthorizationEnabled();
if (toUserIds.size() == 0) throw new IllegalArgumentException("toUserIds size 0");
if (toUserIds.size() == 1) {
return addTagToPhoto(photoId, toUserIds.get(0));
}
List> tags = new ArrayList>(toUserIds.size());
for (String toUserId : toUserIds) {
Map map = new HashMap(1);
map.put("tag_uid", toUserId);
tags.add(map);
}
HttpResponse res = post(buildEndpoint(photoId, "tags"), new HttpParameter[]{new HttpParameter("tags", new JSONArray(tags).toString())});
return Boolean.valueOf(res.asString().trim());
}
public boolean updateTagOnPhoto(String photoId, TagUpdate tagUpdate) throws FacebookException {
return addTagToPhoto(photoId, tagUpdate);
}
public boolean deleteTagOnPhoto(String photoId, String toUserId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(photoId, "tags"), new HttpParameter[]{new HttpParameter("to", toUserId)});
return Boolean.valueOf(res.asString().trim());
}
public String postPhoto(Media source) throws FacebookException {
return postPhoto("me", source);
}
public String postPhoto(PhotoUpdate photoUpdate) throws FacebookException {
return postPhoto("me", photoUpdate);
}
public String postPhoto(String userId, Media source) throws FacebookException {
return postPhoto(userId, new PhotoUpdate(source));
}
public String postPhoto(String userId, PhotoUpdate photoUpdate) throws FacebookException {
ensureAuthorizationEnabled();
JSONObject json = post(buildEndpoint(userId, "photos"), photoUpdate.asHttpParameterArray()).asJSONObject();
return getRawString("id", json);
}
public boolean deletePhoto(String photoId) throws FacebookException {
HttpResponse res = delete(buildEndpoint(photoId));
return Boolean.valueOf(res.asString().trim());
}
/* Poke Methods */
public ResponseList getPokes() throws FacebookException {
return getPokes("me", null);
}
public ResponseList getPokes(Reading reading) throws FacebookException {
return getPokes("me", reading);
}
public ResponseList getPokes(String userId) throws FacebookException {
return getPokes(userId, null);
}
public ResponseList getPokes(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createPokeList(get(buildEndpoint(userId, "pokes", reading)));
}
/* Question Methods */
public ResponseList