freshplanet / ANE-Facebook

Air Native Extension (iOS and Android) for the Facebook mobile SDK
Apache License 2.0
221 stars 123 forks source link

Can't invite friends to app via GameRequestDialog #224

Closed rfatkullin closed 7 years ago

rfatkullin commented 9 years ago

Hi there! I faced with problem: some unclear reasons invite dialog is not shown. My code:

var params:FBGameRequestContent = new FBGameRequestContent();

params.title = "APP REQUEST";
params.message = "Hello here!"  
params.recipients = friends;
params.setActionType(FBGameRequestActionType.NONE);

_facebook.gameRequestDialog(params, false, onInviteComplete);

Where friends is array that contains friends invite-tokens Facebook dialog window doesn't appear(((( I would be very grateful for any help!

josaliba commented 9 years ago

Hey guys,

I'm also getting the same problem here. I am using your new ANE (for FB sdk 4.6.0) but I am not able to call FBGameRequestContent

I have noticed in my logs that I'm always getting

09-17 15:55:16.614 2292-2349/? I/power﹕ *\ release_dvfs_lock : lockType : 1 09-17 15:55:16.614 2292-2349/? D/PowerManagerService﹕ releaseDVFSLockLocked : all DVFS_MIN_LIMIT are released 09-17 15:55:16.614 2292-2349/? W/ActivityManager﹕ mDVFSLock.release()

Thank you in advance for your help

rfatkullin commented 9 years ago

Solve problem with code below.

public class GameRequestDialogFunction extends BaseFunction implements FREFunction
{
    public FREObject call(FREContext context, FREObject[] args)
    {
        super.call(context, args);

        String defaultMessage = "Hi there!";
        String to = "";
        String defaultTitle = "Go to play with me!";

        String message = getStringProperty(args[0], "message");
        List<String> toList = getStringListProperty(args[0], "recipients");
        String title = getStringProperty(args[0], "title");
        String callback = getStringFromFREObject(args[2]);

        if (message == null)
            message = defaultMessage;

        if (toList != null)
        {
            for (int i = 0; i < toList.size(); i++) {
                to += toList.get(i);

                if (i != toList.size() - 1)
                    to += ",";
            }
        }

        if (title == null)
            title = defaultTitle;

        AirFacebookExtension.log("GameRequestDialogFunction");

        GameRequestContent content = new GameRequestContent.Builder()
        .setMessage(message)
        .setTo(to)
        .build();

        CallbackManager callbackManager = CallbackManager.Factory.create();

        GameRequestDialog requestDialog = new GameRequestDialog(context.getActivity());
        requestDialog.registerCallback(callbackManager, new FacebookCallback<GameRequestDialog.Result>()
                                       {
                                           public void onSuccess(GameRequestDialog.Result result) {
                                               AirFacebookExtension.log("Friends invite successfully finished!");
                                           }

                                           public void onCancel() {
                                               AirFacebookExtension.log("Friends inviting canceled!");
                                           }

                                           public void onError(FacebookException error) {
                                               AirFacebookExtension.log("Friends inviting finished with errors!");
                                           }
                                       });

        requestDialog.show(content);

        return null;
    }
}
nodrock commented 9 years ago

Don't you miss call to callbackManager.onActivityResult(requestCode, resultCode, data); in this code? Are you sure you got result from requestDialog?

josaliba commented 9 years ago

Hey @nodrock

After debugging, it seems that the problem is coming from the extra parameters we're sending in the intent. More precisely, it is coming from this line (GameRequestDialogFunction line. 55):

    i.putExtra(GameRequestActivity.extraPrefix + ".content", content);

As soon as I comment this line, everything works as expected.

The workaround I did to solve the problem is that I'm passing all the parameters required to create a GameRequestContent in my intent, and I'm building my GameRequestContent in the GameRequestActivity itself.

I am not sure why is this happening, I'm new to android development so any help will be really appreciated :)

Thanks in advance

nodrock commented 9 years ago

Yes there is problem in current version of FB Android SDK (parcelable issues). I made pull request to FB and I have already fixed it in my branch of this ANE. You can check it here. Or you can download newest release here.