From dbb8a30e7030ba131c48ff5b26f749a6ae47d56f Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Thu, 28 Nov 2013 16:30:34 +0200 Subject: [PATCH 1/9] Added sync publish option --- .../com/sromku/simple/fb/SimpleFacebook.java | 357 +++++++++--------- 1 file changed, 174 insertions(+), 183 deletions(-) diff --git a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java index d9ac7fd..08f55ab 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java +++ b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java @@ -805,6 +805,23 @@ public void onCompleted(Response response) } } } + + /** + * + * Publish {@link Feed} on the wall.
+ *
+ * + * Permission:
+ * {@link Permissions#PUBLISH_ACTION} + * + * @param feed The feed to publish. Use {@link Feed.Builder} to create a new Feed + * @param onPublishListener The listener for publishing action + * @see https://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/ + */ + public void publish(final Feed feed, final OnPublishListener onPublishListener) + { + publish(feed, onPublishListener, true); + } /** * @@ -816,9 +833,10 @@ public void onCompleted(Response response) * * @param feed The feed to publish. Use {@link Feed.Builder} to create a new Feed * @param onPublishListener The listener for publishing action + * @param async should the call be made in an async task. * @see https://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/ */ - public void publish(final Feed feed, final OnPublishListener onPublishListener) + public void publish(final Feed feed, final OnPublishListener onPublishListener, final boolean async) { // if we are logged in if (isLogin()) @@ -843,7 +861,7 @@ public void publish(final Feed feed, final OnPublishListener onPublishListener) @Override public void onSuccess() { - publishImpl(feed, onPublishListener); + publishImpl(feed, onPublishListener, async); } @Override @@ -864,7 +882,7 @@ public void onNotAcceptingPermissions() } else { - publishImpl(feed, onPublishListener); + publishImpl(feed, onPublishListener, async); } } else @@ -891,6 +909,20 @@ public void onNotAcceptingPermissions() } } } + + /** + * Publish open graph story.
+ *
+ * + * Permission:
+ * {@link Permissions#PUBLISH_ACTION} + * + * @param openGraph + * @param onPublishListener + */ + public void publish(final Story story, final OnPublishListener onPublishListener) { + publish(story, onPublishListener, true); + } /** * Publish open graph story.
@@ -901,8 +933,9 @@ public void onNotAcceptingPermissions() * * @param openGraph * @param onPublishListener + * @param async */ - public void publish(final Story story, final OnPublishListener onPublishListener) + public void publish(final Story story, final OnPublishListener onPublishListener, final boolean async) { if (isLogin()) { @@ -927,7 +960,7 @@ public void publish(final Story story, final OnPublishListener onPublishListener @Override public void onSuccess() { - publishImpl(story, onPublishListener); + publishImpl(story, onPublishListener, async); } @Override @@ -949,7 +982,7 @@ public void onNotAcceptingPermissions() } else { - publishImpl(story, onPublishListener); + publishImpl(story, onPublishListener, async); } } else @@ -976,6 +1009,31 @@ public void onNotAcceptingPermissions() } } } + + /** + * Publish photo to specific album. You can use {@link #getAlbums(OnAlbumsRequestListener)} to retrieve + * all user's albums.
+ *
+ * + * Permission:
+ * {@link Permissions#PUBLISH_STREAM}
+ *
+ * + * Important:
+ * - The user must own the album
+ * - The album should not be full (Max: 200 photos). Check it by {@link Album#getCount()}
+ * - The app can add photos to the album
+ * - The privacy setting of the app should be at minimum as the privacy setting of the album ( + * {@link Album#getPrivacy()} + * + * @param photo The photo to upload + * @param albumId The album to which the photo should be uploaded + * @param onPublishListener The callback listener + */ + public void publish(final Photo photo, final String albumId, final OnPublishListener onPublishListener) + { + publish(photo, albumId, onPublishListener, true); + } /** * Publish photo to specific album. You can use {@link #getAlbums(OnAlbumsRequestListener)} to retrieve @@ -996,8 +1054,9 @@ public void onNotAcceptingPermissions() * @param photo The photo to upload * @param albumId The album to which the photo should be uploaded * @param onPublishListener The callback listener + * @param async should the call be made in async task */ - public void publish(final Photo photo, final String albumId, final OnPublishListener onPublishListener) + public void publish(final Photo photo, final String albumId, final OnPublishListener onPublishListener, final boolean async) { if (isLogin()) { @@ -1021,7 +1080,7 @@ public void publish(final Photo photo, final String albumId, final OnPublishList @Override public void onSuccess() { - publishImpl(photo, albumId, onPublishListener); + publishImpl(photo, albumId, onPublishListener, async); } @Override @@ -1043,7 +1102,7 @@ public void onNotAcceptingPermissions() } else { - publishImpl(photo, albumId, onPublishListener); + publishImpl(photo, albumId, onPublishListener, async); } } else @@ -1348,191 +1407,123 @@ public static Session getOpenSession() public void clean() { mActivity = null; + } + + private static void publishImpl(Feed feed, final OnPublishListener onPublishListener, boolean async) + { + if (async) + { + publishAsync("me/feed", feed.getBundle(), onPublishListener); + } + else + { + publishSync("me/feed", feed.getBundle(), onPublishListener); + } } - private static void publishImpl(Feed feed, final OnPublishListener onPublishListener) + private static void handlePublishResponse(Response response, OnPublishListener onPublishListener) { - Session session = getOpenSession(); - Request request = new Request(session, "me/feed", feed.getBundle(), HttpMethod.POST, new Request.Callback() - { - @Override - public void onCompleted(Response response) - { - GraphObject graphObject = response.getGraphObject(); - if (graphObject != null) - { - JSONObject graphResponse = graphObject.getInnerJSONObject(); - String postId = null; - try - { - postId = graphResponse.getString("id"); - } - catch (JSONException e) - { - // log - logError("JSON error", e); - } - - FacebookRequestError error = response.getError(); - if (error != null) - { - // log - logError("Failed to publish", error.getException()); - - // callback with 'exception' - if (onPublishListener != null) - { - onPublishListener.onException(error.getException()); - } - } - else - { - // callback with 'complete' - if (onPublishListener != null) - { - onPublishListener.onComplete(postId); - } - } - } - else - { - // log - logError("The GraphObject in Response of publish action has null value. Response=" + response.toString(), null); - - if (onPublishListener != null) - { - onPublishListener.onComplete("0"); - } - } - } - }); - - RequestAsyncTask task = new RequestAsyncTask(request); - task.execute(); + GraphObject graphObject = response.getGraphObject(); + if (graphObject != null) + { + JSONObject graphResponse = graphObject.getInnerJSONObject(); + String postId = null; + try + { + postId = graphResponse.getString("id"); + } + catch (JSONException e) + { + // log + logError("JSON error", e); + } + + FacebookRequestError error = response.getError(); + if (error != null) + { + // log + logError("Failed to publish", error.getException()); + + // callback with 'exception' + if (onPublishListener != null) + { + onPublishListener.onException(error.getException()); + } + } + else + { + // callback with 'complete' + if (onPublishListener != null) + { + onPublishListener.onComplete(postId); + } + } + } + else + { + // log + logError("The GraphObject in Response of publish action has null value. Response=" + response.toString(), null); + + if (onPublishListener != null) + { + onPublishListener.onComplete("0"); + } + } } - - private static void publishImpl(Story story, final OnPublishListener onPublishListener) + + private static class RequestCallback implements Request.Callback { + private OnPublishListener onPublishListener; + + public RequestCallback(OnPublishListener onPublishListener) { + this.onPublishListener = onPublishListener; + } + + @Override + public void onCompleted(Response response) + { + handlePublishResponse(response, onPublishListener); + } + } + + private static void publishSync(String graphPath, Bundle parameters, final OnPublishListener onPublishListener) + { + Session session = getOpenSession(); + Request request = new Request(session, graphPath, parameters, HttpMethod.POST); + handlePublishResponse(request.executeAndWait(), onPublishListener); + } + + private static void publishAsync(String graphPath, Bundle parameters, final OnPublishListener onPublishListener) + { + Session session = getOpenSession(); + Request request = new Request(session, graphPath, parameters, HttpMethod.POST, new RequestCallback(onPublishListener)); + RequestAsyncTask task = new RequestAsyncTask(request); + task.execute(); + } + + private static void publishImpl(Story story, final OnPublishListener onPublishListener, boolean async) { - Session session = getOpenSession(); String appNamespace = mConfiguration.getNamespace(); - Request request = new Request(session, story.getGraphPath(appNamespace), story.getActionBundle(), HttpMethod.POST, new Request.Callback() + if (async) { - @Override - public void onCompleted(Response response) - { - GraphObject graphObject = response.getGraphObject(); - if (graphObject != null) - { - JSONObject graphResponse = graphObject.getInnerJSONObject(); - String postId = null; - try - { - postId = graphResponse.getString("id"); - } - catch (JSONException e) - { - // log - logError("JSON error", e); - } - - FacebookRequestError error = response.getError(); - if (error != null) - { - // log - logError("Failed to publish", error.getException()); - - // callback with 'exception' - if (onPublishListener != null) - { - onPublishListener.onException(error.getException()); - } - } - else - { - // callback with 'complete' - if (onPublishListener != null) - { - onPublishListener.onComplete(postId); - } - } - } - else - { - // log - logError("The GraphObject in Response of publish action has null value. Response=" + response.toString(), null); - - if (onPublishListener != null) - { - onPublishListener.onComplete("0"); - } - } - } - }); - - RequestAsyncTask task = new RequestAsyncTask(request); - task.execute(); + publishAsync(story.getGraphPath(appNamespace), story.getActionBundle(), onPublishListener); + } + else + { + publishSync(story.getGraphPath(appNamespace), story.getActionBundle(), onPublishListener); + } } - private static void publishImpl(Photo photo, String albumId, final OnPublishListener onPublishListener) + private static void publishImpl(Photo photo, String albumId, final OnPublishListener onPublishListener, boolean async) { - Session session = getOpenSession(); - Request request = new Request(session, albumId + "/photos", photo.getBundle(), HttpMethod.POST, new Request.Callback() - { - @Override - public void onCompleted(Response response) - { - GraphObject graphObject = response.getGraphObject(); - if (graphObject != null) - { - JSONObject graphResponse = graphObject.getInnerJSONObject(); - String postId = null; - try - { - postId = graphResponse.getString("id"); - } - catch (JSONException e) - { - // log - logError("JSON error", e); - } - - FacebookRequestError error = response.getError(); - if (error != null) - { - // log - logError("Failed to publish", error.getException()); - - // callback with 'exception' - if (onPublishListener != null) - { - onPublishListener.onException(error.getException()); - } - } - else - { - // callback with 'complete' - if (onPublishListener != null) - { - onPublishListener.onComplete(postId); - } - } - } - else - { - // log - logError("The GraphObject in Response of publish action has null value. Response=" + response.toString(), null); - - if (onPublishListener != null) - { - onPublishListener.onComplete("0"); - } - } - } - }); - - RequestAsyncTask task = new RequestAsyncTask(request); - task.execute(); + if (async) + { + publishAsync(albumId + "/photos", photo.getBundle(), onPublishListener); + } + else + { + publishAsync(albumId + "/photos", photo.getBundle(), onPublishListener); + } } private void openInviteDialog(Activity activity, Bundle params, final OnInviteListener onInviteListener) From 24ce6533ed79d817367fa79e8009bd2882f9af0a Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Thu, 28 Nov 2013 18:18:31 +0200 Subject: [PATCH 2/9] Added publish og.like --- .../com/sromku/simple/fb/SimpleFacebook.java | 116 ++++++++++++++++++ .../com/sromku/simple/fb/entities/Like.java | 90 ++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 Simple Facebook/src/com/sromku/simple/fb/entities/Like.java diff --git a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java index 08f55ab..e2d68a3 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java +++ b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java @@ -31,6 +31,7 @@ import com.facebook.widget.WebDialog; import com.sromku.simple.fb.entities.Album; import com.sromku.simple.fb.entities.Feed; +import com.sromku.simple.fb.entities.Like; import com.sromku.simple.fb.entities.Photo; import com.sromku.simple.fb.entities.Profile; import com.sromku.simple.fb.entities.Story; @@ -806,6 +807,110 @@ public void onCompleted(Response response) } } + /** + * + * Publish {@link Like}.
+ *
+ * + * Permission:
+ * {@link Permissions#PUBLISH_ACTION} + * + * @param like The like object to publish. Use {@link Like.Builder} to create a new Like + * @param onPublishListener The listener for publishing action + * @See https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes + */ + public void publish(final Like like, final OnPublishListener onPublishListener) + { + publish(like, onPublishListener, true); + } + + /** + * + * Publish {@link Like}.
+ *
+ * + * Permission:
+ * {@link Permissions#PUBLISH_ACTION} + * + * @param like The like object to publish. Use {@link Like.Builder} to create a new Like + * @param onPublishListener The listener for publishing action + * @param async should the call be made via async task + * @See https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes + */ + public void publish(final Like like, final OnPublishListener onPublishListener, final boolean async) + { + // if we are logged in + if (isLogin()) + { + // if we defined the publish permission + if (mConfiguration.getPublishPermissions().contains(Permissions.PUBLISH_ACTION.getValue())) + { + // callback with 'thinking' + if (onPublishListener != null) + { + onPublishListener.onThinking(); + } + + /* + * Check if session to facebook has 'publish_action' permission. If not, we will ask user for + * this permission. + */ + if (!getOpenSessionPermissions().contains(Permissions.PUBLISH_ACTION.getValue())) + { + mSessionStatusCallback.mOnReopenSessionListener = new OnReopenSessionListener() + { + @Override + public void onSuccess() + { + publishImpl(like, onPublishListener, async); + } + + @Override + public void onNotAcceptingPermissions() + { + // this fail can happen when user doesn't accept the publish permissions + String reason = Errors.getError(ErrorMsg.CANCEL_PERMISSIONS_PUBLISH, String.valueOf(mConfiguration.getPublishPermissions())); + logError(reason, null); + if (onPublishListener != null) + { + onPublishListener.onFail(reason); + } + } + }; + + // extend publish permissions automatically + extendPublishPermissions(); + } + else + { + publishImpl(like, onPublishListener, async); + } + } + else + { + String reason = Errors.getError(ErrorMsg.PERMISSIONS_PUBLISH, Permissions.PUBLISH_ACTION.getValue()); + logError(reason, null); + + // callback with 'fail' due to insufficient permissions + if (onPublishListener != null) + { + onPublishListener.onFail(reason); + } + } + } + else + { + // callback with 'fail' due to not being loged + if (onPublishListener != null) + { + String reason = Errors.getError(ErrorMsg.LOGIN); + logError(reason, null); + + onPublishListener.onFail(reason); + } + } + } + /** * * Publish {@link Feed} on the wall.
@@ -1409,6 +1514,17 @@ public void clean() mActivity = null; } + private static void publishImpl(Like like, final OnPublishListener onPublishListener, boolean async) { + if (async) + { + publishAsync("me/og.likes", like.getBundle(), onPublishListener); + } + else + { + publishSync("me/og.likes", like.getBundle(), onPublishListener); + } + } + private static void publishImpl(Feed feed, final OnPublishListener onPublishListener, boolean async) { if (async) diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Like.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Like.java new file mode 100644 index 0000000..4876be3 --- /dev/null +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Like.java @@ -0,0 +1,90 @@ +package com.sromku.simple.fb.entities; + +import org.json.JSONObject; + +import android.os.Bundle; + +public class Like { + + private Bundle mBundle = null; + + private Like(Builder builder) + { + this.mBundle = builder.mBundle; + } + + public Bundle getBundle() + { + return mBundle; + } + + public static class Builder + { + Bundle mBundle; + JSONObject mProperties = new JSONObject(); + JSONObject mActions = new JSONObject(); + + static class Parameters + { + public static final String OBJECT = "object"; + public static final String IMAGE = "image"; + public static final String LINK = "link"; + public static final String TITLE = "title"; + } + + public Builder() + { + mBundle = new Bundle(); + } + + /** + * The object that was liked (this is actually the link to the url with facebook meta tags) + * + * @param object + * @return {@link Builder} + */ + public Builder setObject(String object) + { + mBundle.putString(Parameters.OBJECT, object); + return this; + } + + /** + * The URL of an image that will override the image from the object meta tags + * + * @param image + * @return {@link Builder} + */ + public Builder setImage(String image) { + mBundle.putString(Parameters.IMAGE, image); + return this; + } + + /** + * The redirect link when people click the like story + * + * @param link + * @return {@link Builder} + */ + public Builder setLink(String link) { + mBundle.putString(Parameters.LINK, link); + return this; + } + + /** + * The title of the item that was liked. + * + * @param link + * @return {@link Builder} + */ + public Builder setTitle(String title) { + mBundle.putString(Parameters.TITLE, title); + return this; + } + + public Like build() + { + return new Like(this); + } + } +} From 41f1fc31c2225c15109b1c84b97c4dfb7ee068c4 Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Sun, 1 Dec 2013 12:41:05 +0200 Subject: [PATCH 3/9] Added me/groups get action --- .../com/sromku/simple/fb/SimpleFacebook.java | 107 ++++++++++++++++++ .../com/sromku/simple/fb/entities/Group.java | 36 ++++++ 2 files changed, 143 insertions(+) create mode 100644 Simple Facebook/src/com/sromku/simple/fb/entities/Group.java diff --git a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java index e2d68a3..aa8fbb2 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java +++ b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java @@ -31,6 +31,7 @@ import com.facebook.widget.WebDialog; import com.sromku.simple.fb.entities.Album; import com.sromku.simple.fb.entities.Feed; +import com.sromku.simple.fb.entities.Group; import com.sromku.simple.fb.entities.Like; import com.sromku.simple.fb.entities.Photo; import com.sromku.simple.fb.entities.Profile; @@ -415,6 +416,101 @@ public void onCompleted(Response response) } } + /** + * Get my groups from Facebook + * + * @param OnGroupsRequestListener + * + */ + public void getGroups(final OnGroupsRequestListener onGroupsRequestListener) + { + // if we are logged in + if (isLogin()) + { + // move these params to method call parameters + Session session = getOpenSession(); + Request request = new Request(session, "me/groups", null, HttpMethod.GET, new Request.Callback() + { + @Override + public void onCompleted(Response response) + { + logError(response.toString(), null); + + FacebookRequestError error = response.getError(); + if (error != null) + { + // log + logError("failed to get groups", error.getException()); + + // callback with 'exception' + if (onGroupsRequestListener != null) + { + onGroupsRequestListener.onException(error.getException()); + } + } + else + { + GraphObject graphObject = response.getGraphObject(); + if (graphObject != null) + { + JSONObject graphResponse = graphObject.getInnerJSONObject(); + try { + JSONArray result = graphResponse.getJSONArray("data"); + if (result != null) + { + List groups = new ArrayList(); + int size = result.length(); + for (int i = 0; i < size; i++) + { + logError("Adding group " + result.getJSONObject(i), null); + + groups.add(Group.create(result.getJSONObject(i))); + } + + if (onGroupsRequestListener != null) + { + onGroupsRequestListener.onComplete(groups); + } + } + else if (onGroupsRequestListener != null) + { + onGroupsRequestListener.onFail("data array is null"); + } + } catch (JSONException e) { + if (onGroupsRequestListener != null) + { + onGroupsRequestListener.onException(e); + } + } + } else if (onGroupsRequestListener != null) { + onGroupsRequestListener.onFail("graphObject in null"); + } + } + } + }); + + RequestAsyncTask task = new RequestAsyncTask(request); + task.execute(); + + // callback with 'thinking' + if (onGroupsRequestListener != null) + { + onGroupsRequestListener.onThinking(); + } + } + else + { + String reason = Errors.getError(ErrorMsg.LOGIN); + logError(reason, null); + + // callback with 'fail' due to not being loged + if (onGroupsRequestListener != null) + { + onGroupsRequestListener.onFail(reason); + } + } + } + /** * Get albums * @@ -2019,6 +2115,17 @@ public interface OnFriendsRequestListener extends OnActionListener void onComplete(List friends); } + /** + * On groups request listener + * + * @author tamir7 + * + */ + public interface OnGroupsRequestListener extends OnActionListener + { + void onComplete(List groups); + } + /** * On get app requests listener * diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Group.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Group.java new file mode 100644 index 0000000..2e85b28 --- /dev/null +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Group.java @@ -0,0 +1,36 @@ +package com.sromku.simple.fb.entities; + +import org.json.JSONObject; + +public class Group { + private String mId; + private String mName; + private int mBookmarkOrder; + + private Group(JSONObject jsonObject) + { + mId = jsonObject.optString("id"); + mName = jsonObject.optString("name"); + mBookmarkOrder = jsonObject.optInt("bookmark_order"); + } + + public static Group create(JSONObject jsonObject) + { + return new Group(jsonObject); + } + + public String getId() + { + return mId; + } + + public String getName() + { + return mName; + } + + public int getBookmarkOrder() + { + return mBookmarkOrder; + } +} From ffb1c856245267f7ec12ac334be9256dda63dff5 Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Sun, 1 Dec 2013 12:51:07 +0200 Subject: [PATCH 4/9] Added some logError prints to getGroups function --- .../src/com/sromku/simple/fb/SimpleFacebook.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java index aa8fbb2..d023bc8 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java +++ b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java @@ -434,8 +434,6 @@ public void getGroups(final OnGroupsRequestListener onGroupsRequestListener) @Override public void onCompleted(Response response) { - logError(response.toString(), null); - FacebookRequestError error = response.getError(); if (error != null) { @@ -462,8 +460,6 @@ public void onCompleted(Response response) int size = result.length(); for (int i = 0; i < size; i++) { - logError("Adding group " + result.getJSONObject(i), null); - groups.add(Group.create(result.getJSONObject(i))); } @@ -474,15 +470,18 @@ public void onCompleted(Response response) } else if (onGroupsRequestListener != null) { + logError("data array is null", null); onGroupsRequestListener.onFail("data array is null"); } } catch (JSONException e) { if (onGroupsRequestListener != null) { + logError("Exception while parsing json object", e); onGroupsRequestListener.onException(e); } } } else if (onGroupsRequestListener != null) { + logError("graphObject is null", null); onGroupsRequestListener.onFail("graphObject in null"); } } From 45e9a9360cfa6d16b22b1ab1526e4beafed54d3a Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Sun, 1 Dec 2013 14:38:11 +0200 Subject: [PATCH 5/9] Added the ability to post to group feed --- .../com/sromku/simple/fb/SimpleFacebook.java | 4 +-- .../com/sromku/simple/fb/entities/Feed.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java index d023bc8..b3bdaa5 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java +++ b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java @@ -1624,11 +1624,11 @@ private static void publishImpl(Feed feed, final OnPublishListener onPublishList { if (async) { - publishAsync("me/feed", feed.getBundle(), onPublishListener); + publishAsync(feed.getGraphPath(), feed.getBundle(), onPublishListener); } else { - publishSync("me/feed", feed.getBundle(), onPublishListener); + publishSync(feed.getGraphPath(), feed.getBundle(), onPublishListener); } } diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Feed.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Feed.java index 254e5c9..51b3155 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/entities/Feed.java +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Feed.java @@ -16,10 +16,23 @@ public class Feed { private Bundle mBundle = null; + private String mGroupId = null; private Feed(Builder builder) { this.mBundle = builder.mBundle; + this.mGroupId = builder.mGroupId; + } + + public String getGraphPath() + { + if (mGroupId == null) { + return "me/feed"; + } + else + { + return mGroupId + "/feed/"; + } } public Bundle getBundle() @@ -32,6 +45,7 @@ public static class Builder Bundle mBundle; JSONObject mProperties = new JSONObject(); JSONObject mActions = new JSONObject(); + String mGroupId; static class Parameters { @@ -123,6 +137,18 @@ public Builder setDescription(String description) mBundle.putString(Parameters.DESCRIPTION, description); return this; } + + /** + * If group ID is specified, the post will be to the group feed and not the users feed. + * + * @param groupId + * @return {@link Builder} + */ + public Builder setGroupId(String groupId) + { + mGroupId = groupId; + return this; + } /** * Object of key/value pairs which will appear in the stream attachment beneath the description, with From bb16b8ca0d5078eff31c382690128f8da8649bf7 Mon Sep 17 00:00:00 2001 From: reemsherman Date: Tue, 17 Dec 2013 15:56:35 +0200 Subject: [PATCH 6/9] Added new functions --- .../src/com/sromku/simple/fb/SimpleFacebook.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java index b3bdaa5..428d72a 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java +++ b/Simple Facebook/src/com/sromku/simple/fb/SimpleFacebook.java @@ -1210,6 +1210,14 @@ public void onNotAcceptingPermissions() } } + public boolean checkForPublishPermissions() { + return getOpenSessionPermissions().contains(Permissions.PUBLISH_ACTION.getValue()); + } + + public void requestPublishPermissions() { + extendPublishPermissions(); + } + /** * Publish photo to specific album. You can use {@link #getAlbums(OnAlbumsRequestListener)} to retrieve * all user's albums.
From e5d0c740f59da998279b1360ba072e84664492ea Mon Sep 17 00:00:00 2001 From: reemsherman Date: Tue, 17 Dec 2013 15:57:06 +0200 Subject: [PATCH 7/9] Maybe not needed --- Simple Facebook/.classpath | 18 +++++++++--------- Simple Facebook/project.properties | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Simple Facebook/.classpath b/Simple Facebook/.classpath index e299f21..5381274 100644 --- a/Simple Facebook/.classpath +++ b/Simple Facebook/.classpath @@ -1,9 +1,9 @@ - - - - - - - - - + + + + + + + + + diff --git a/Simple Facebook/project.properties b/Simple Facebook/project.properties index db721fd..d5fdd1a 100644 --- a/Simple Facebook/project.properties +++ b/Simple Facebook/project.properties @@ -11,5 +11,6 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-8 +target=Google Inc.:Google APIs:19 android.library=true +android.library.reference.1=../../Desktop/Programs/facebook-android-sdk-3.5/facebook From 5d5a584a646f094c8bce7a0ff716690e4e8f9f65 Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Thu, 23 Jan 2014 20:07:05 +0200 Subject: [PATCH 8/9] removed warning --- Simple Facebook/src/com/sromku/simple/fb/entities/Story.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Story.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Story.java index db61691..df7633a 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/entities/Story.java +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Story.java @@ -203,7 +203,8 @@ String getObjectUrl() return mHostFileUrl + "?" + encodeUrl(mBundle); } - private static String encodeUrl(Bundle parameters) + @SuppressWarnings("deprecation") + private static String encodeUrl(Bundle parameters) { if (parameters == null) { From 1734f4fb83a3619f075ae873ab37fc76255061e8 Mon Sep 17 00:00:00 2001 From: Tamir Shomer Date: Sun, 26 Jan 2014 11:34:39 +0200 Subject: [PATCH 9/9] Removed warning --- Simple Facebook/src/com/sromku/simple/fb/entities/Checkins.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Checkins.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Checkins.java index 774b8e7..4f96de6 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/entities/Checkins.java +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Checkins.java @@ -3,7 +3,6 @@ import org.json.JSONObject; import com.facebook.model.GraphObject; -import com.sromku.simple.fb.utils.Utils; public class Checkins { public static final String ID = "id";