2

How can I check if a user has removed my app from his facebook apps before calling a dialog request.

Session session = Session.getActiveSession();
    if (session != null) {
        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions)) {
            // //Log.d(TAG,
            // "the session doesnt have the permissions");
            Session.OpenRequest openRequest = null;
            openRequest = new Session.OpenRequest(this);
            openRequest.setPermissions(PERMISSIONS);
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
            session.openForPublish(openRequest);
            return;
        } else {
            // //Log.d(TAG,
            // "the session has enough permissions");
            displayFacebookDialog();
        }
    }

The else is still being called even that the user has deleted the app.

public static WebDialog displayFacebookDialog(String picture, OnCompleteListener callback,
        Activity activity) {
    Bundle data = new Bundle();
    data.putString("name", activity.getString(R.string.app_name));
    data.putString("caption", activity.getString(R.string.facebook_caption));
    data.putString("description",
            activity.getString(R.string.facebook_description));
    data.putString("link", activity.getString(R.string.facebook_link));
    data.putString("picture", picture);
    WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity,
            Session.getActiveSession(), data)).setOnCompleteListener(callback).build();
    return feedDialog;
}
user1940676
  • 4,348
  • 9
  • 44
  • 73
  • Does this solution meet your needs? http://stackoverflow.com/questions/6711295/how-to-check-if-facebook-is-installed-android – Jonathan Jul 14 '13 at 16:45
  • @Jonathan I want to check if he has removed my app from his 'facebook apps'. sorry for the ambiguous explanation I have edited my question. – user1940676 Jul 15 '13 at 06:14

1 Answers1

2

Alright, so it looks like the permissions are bound to the Session object at creation and no request to confirm them is made when you call getPermissions. What this means is that you can have the out of sync state you're describing where your access token is no longer valid, but your application doesn't know that.

I assume what is happening is that you're getting a FacebookRequestError in your postStatusUpdate() method. You should check for this error in your callback and then put the login logic into that method.

Jonathan
  • 3,369
  • 4
  • 22
  • 27
  • I am trying to show a facebook web dialog to the user, and all he see's is a web dialog with an 'error' message. – user1940676 Jul 16 '13 at 06:36
  • Alright, so the problem effectively boils down to you having stale data on your client. The only way I can imagine around that is for you to make a request the facebook [permissions API](https://developers.facebook.com/docs/facebook-login/permissions/#adding) and confirming your permissions before making a request. Have you tried doing that? – Jonathan Jul 20 '13 at 04:47