I have implemented the login authentication in my app, i know how to share, but im getting crazy about the like, because im never getting a positive response. So...how can i like a post from my android app with facebook sdk, by requesting publish permissions?
Asked
Active
Viewed 261 times
0

tshepang
- 12,111
- 21
- 91
- 136

WitaloBenicio
- 3,395
- 5
- 25
- 32
-
check this post: http://stackoverflow.com/a/23853937/1891118 your task is solved by simple library. – Oleksii K. Jun 14 '14 at 18:36
1 Answers
1
Its work for me.
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions", "publish_stream");
public void likeThis() {
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
if (setPermissions(session, newPermissionsRequest))
return;
}
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
if (response != null) {
FacebookRequestError error = response.getError();
if (error != null) {
// error
} else {
// success
}
} else {
MessageToast toast = MessageToast.getInstance(mContext);
toast.show("Tente novamente mais tarde", MessageToast.ALERT);
}
}
};
Request request = new Request(session, "1442581505974136/likes", null, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}else{
// not logged
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
private boolean setPermissions(final Session session, final NewPermissionsRequest newPermissionsRequest) {
try {
Log.i(TAG, "Getting a new permission...");
session.requestNewPublishPermissions(newPermissionsRequest);
return true;
} catch (IllegalStateException e) {
Log.e("setPermissions","[IllegalStateException] \n" + e.getMessage());
pendingPublishReauthorization = false;
return false;
} catch (UnsupportedOperationException e) {
Log.e("setPermissions","[UnsupportedOperationException] \n" + e.getMessage());
pendingPublishReauthorization = false;
return false;
}
}
But sometime, I can't like some fb_id. I don't know why, yet..

Fabricioraphael
- 195
- 1
- 9
-
What is productbean? A class that you made? Why arent you using this product object in yout method? And that method isSubsetOf()? – WitaloBenicio Mar 07 '14 at 13:44
-
Please, post the code of the methods that you use inside of like method too. :) – WitaloBenicio Mar 07 '14 at 13:47
-
sory, I added the method. and the model ProductBean don't matter. I used to get the facebook_post_id which was persistent. – Fabricioraphael Mar 07 '14 at 14:27
-
-
Which id returned by JSON you pass to the method? "object_id" or the second part (after "_") of "id"? – WitaloBenicio Mar 07 '14 at 14:33
-
Thanks man. Finally i found a solution...your solution. Thanks man...melhor...VALEU MANO, TU ME SALVOU! iaheiuae – WitaloBenicio Mar 07 '14 at 14:50
-
the response when success is: {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":true}}, error: null, isFromCache:false} I can't reproduce the error case. – Fabricioraphael Mar 07 '14 at 14:51
-
-
Cara, simplesmente parou de funcionar...de manhã tava funcionando de boa. E agora, já elvis. :/ – WitaloBenicio Mar 07 '14 at 23:11