如何在调用对话请求之前检查用户是否已从他的 Facebook 应用程序中删除了我的应用程序。
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();
}
}
即使用户删除了应用程序,else 仍然会被调用。
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;
}