AppInviteDialog not working in Android Facebook SDK 4.0

梦想与她 提交于 2019-12-12 08:12:01

问题


After long research and trying to fix this on my own, I haven't found any acceptable working result.

Following this documentation I'm trying to invite friends to my app. All elements, such as share buttons are working properly.

The only problem are with "Invite to app" dialog. After selecting a friend, the dialog are showing red alert icon and "send" button is turns into "retry" button.

I have tried fix this in many ways - configure my app in FB dev page (like changing app category: game, travel .etc), adding new permission for sharing (but I haven't found, that inviting is required it), using GamesRequests (but my app isn't a game, it's android + canvas app). So I have returned again to AppInviteDialog.

Also, I have trying to use own instance of it, with listeners, instead of static class.

inviteDialog = new AppInviteDialog(this);
inviteDialog.registerCallback(callbackManager, new FacebookCallback<Result>() {
    @Override
    public void onSuccess(Result result) {
        Log.i(TAG, "MainACtivity, InviteCallback - SUCCESS!");
    }

    @Override
    public void onCancel() {
        Log.i(TAG, "MainACtivity, InviteCallback - CANCEL!");
    }

    @Override
    public void onError(FacebookException error) {
        Log.e(TAG, "MainACtivity, InviteCallback - ERROR! " + error.getMessage());
    }
});

And calling it, like in tutorial:

 if(AppInviteDialog.canShow()) {
        AppInviteContent content = new AppInviteContent.Builder()
            .setApplinkUrl(appUrl)
            .setPreviewImageUrl(imagePreviewUrl)
            .build();
            //AppInviteDialog.show(this, content); //static
        inviteDialog.show(content); //my instance
  }

But all what i get is:

Edit:

After creating link to my app using AppLinks, and using it in the AppInviteDialog, now all works fine. It's a bit confusing, that in documentation not clearly described, what kind of link need to use: "AppLinks link" or just "app link (link to your fb app)".


回答1:


Is there an error message?

I get this if I don't use an AppLink.

https://developers.facebook.com/quickstarts/1374389166202673/?platform=app-links-host




回答2:


I was having the same issue and my cause was not calling onActivityResult on the facebook CallbackManager. This is how I fixed it:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    facebookCallbackManager = CallbackManager.Factory.create();
    // ...
}

Then here is where I was having the error:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // This is the line I was lacking
    facebookCallbackManager.onActivityResult(requestCode, resultCode, data);
}

After onActivityResult was added, I am getting my callbacks fired:

AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
FacebookCallback callback =  new FacebookCallback<AppInviteDialog.Result>() {
        @Override
        public void onSuccess(AppInviteDialog.Result result) {
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException error) {
        }
    };
appInviteDialog.registerCallback(facebookCallbackManager, callback);
appInviteDialog.show(content);


来源:https://stackoverflow.com/questions/29393848/appinvitedialog-not-working-in-android-facebook-sdk-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!