Android Facebook SDK Share dialogue: never come back.

I am using facebook android sdk v3.5 in my messaging app. For statistics, I need to keep track of whether the message was posted successfully or not. However, I always get null by getting FacebookDialog.getNativeDialogCompletionGesture in onActivityResult()

The code I use is very standard.

Code for calling facebook sharing dialog:

  private void sendToFacebook() { if (!FacebookDialog.canPresentShareDialog(getActivity().getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { return; } FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(getActivity()) .setName(getString(R.string.refer_friend_facebook_name)) .setDescription(getString(R.string.refer_friend_facebook_description)) .setCaption(getString(R.string.facebook_app_name)) .setLink(getString(R.string.web_endpoint)) .setPicture(getString(R.string.facebook_picture_90)) .build(); activity.getFacebookUiHelper().trackPendingDialogCall(shareDialog.present()); } 

The code that I use to process the result of the call:

  @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { facebookUiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() { @Override public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { // track on error } @Override public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { if (FacebookDialog.getNativeDialogDidComplete(data)) { if (FacebookDialog.getNativeDialogCompletionGesture(data) == null || FacebookDialog.COMPLETION_GESTURE_CANCEL.equals(FacebookDialog.getNativeDialogCompletionGesture(data))) { // track cancel } else { // track post } } else { // track cancel } } }); } 

The facebook sdk documentation states that:

FacebookDialog.getNativeDialogCompletionGesture - is available only if the user has logged in to your application using Facebook and executed it. The meaning is "post" or "cancel."

But I can’t understand what exactly they mean by this phrase.

+6
source share
1 answer

This means that you only get the Gesture termination if the user has "authorization" of your application (that is, he clicked on some form of login via the Facebook button in your application and gave your application at least basic permissions).

If they did not, then you will get getNativeDialogDidComplete, which always returns true (regardless of whether the user clicked "Share" or "Cancel") if no error occurred.

+3
source

Source: https://habr.com/ru/post/954626/


All Articles