4

I'm using share dialog to share a link onto the user's timeline but it's not working while the Facebook app is installed. It is functioning properly using the default browser (when the app is uninstalled). Note that FB login is working both with and without the FB app.

This is my code:

if(click_id==R.id.comboshare_fb) //Button click
    {
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // App code
                String userid = loginResult.getAccessToken().getUserId(); //Gets the userid.
                Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancel() {

            }

            @Override
            public void onError(FacebookException error) {

            }

        }); //Login is working

        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {

            }

            @Override
            public void onCancel() {
                Toast.makeText(getApplicationContext(), "Share Cancelled!", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onError(FacebookException error) {

                Log.d("Final Problem", "onError " + error);

            }


        });
        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setQuote("I completed 3X Combo in Wordplay! :)")
                .setContentUrl(Uri.parse("https://i2.wp.com/sbansite.files.wordpress.com/2018/07/yay-you-completed-3-combo-10.png?ssl=1&w=450"))
                .build();

        if(shareDialog.canShow(ShareLinkContent.class))
                {
                    shareDialog.show(linkContent);
                }}

The error that I'm getting from onError() of sharedialog is: D/Final Problem: onError Invalid long: "null"

Any help is welcome, thanks in advance.

P.S. My app is still in development mode at Facebook.

SBan
  • 43
  • 1
  • 7
  • It seems to be happening only with the latest facebook app, works fine in older fb version – varun Jul 10 '18 at 06:30
  • I have the same problem. If I uninstall the Facebook app, the share dialog is probably prompted by the default browser, and it works. Tried to upgrade the `facebook-android-sdk` to the latest `4.34.0` but that doesn't help. – Ambran Jul 10 '18 at 08:53
  • As Day's answer suggests, it is a bug in the lastest FB app. I'm thinking of using just the browser for sharing without even trying out the native app first, like his answer suggests. – SBan Jul 10 '18 at 10:05
  • Yes, Day's fix works for me too. I'm using it as he/she suggested in the `onError` override. Thanks @Day! – Ambran Jul 10 '18 at 11:01
  • Looks like Facebook fixed the bug with their new app update. Now my previous code works just fine. – SBan Jul 12 '18 at 11:34

1 Answers1

4

This is a bug introduced in the latest Facebook app.

Here's a link to the reported issue: https://developers.facebook.com/bugs/647119912303459/

If you want to add a workaround for your users who use this version of the app, you could add something like this in your error-callback:

@Override
public void onError(FacebookException error) {
    if (error != null && error.getMessage().equals("null") {
        // Don't use the app for sharing in case of null-error
        shareDialog.show(linkContent, ShareDialog.Mode.WEB);
    }
}

Sharing via the webview-share works

Day
  • 844
  • 1
  • 9
  • 21
  • Woah! I spent four days trying to figure out where I've been wrong. Thank you so much for this. – SBan Jul 10 '18 at 09:58