6

I was using old implementation of Facebook apprequests dialog in my project like:

 Bundle parameters = new Bundle();
 parameters.putString("message","invite friends message...");
 parameters.putString("data","invite friends data...");
 parameters.putString("title","invite friends dialog title...");

 if (facebook != null){
    facebook.dialog(getActivity(), "apprequests", parameters,
        new Facebook.DialogListener() {
            @Override
            public void onComplete(Bundle values) {
                // todo:
            }
        });
  }

i have found new implementation in facebook doc. App Invites

appLinkUrl = "my app link...";
previewImageUrl = "my image url...";

if (AppInviteDialog.canShow()) {
    AppInviteContent content = new AppInviteContent.Builder()
           .setApplinkUrl(appLinkUrl)
           .setPreviewImageUrl(previewImageUrl)
           .build();
    AppInviteDialog.show(activity, content);
}

Is this right implementation for invite app to friends or any other way? if yes then where would my message and data content would placed.

Or if i am using graph api request like:

 String graphPath="/me/apprequests/";
 GraphRequest request = GraphRequest.newGraphPathRequest(
      accessToken, graphPath, graphCallback);

 Bundle parameters = new Bundle();
 parameters.putString("message","invite friends message...");
 parameters.putString("data","invite friends data...");
 parameters.putString("title","invite friends dialog title...");

 request.setParameters(parameters);
 request.executeAsync();

then getting {"data":[]} in response and no dialog appears. What would be the correct implementation for this?

Akhilesh Dhar Dubey
  • 2,152
  • 2
  • 25
  • 39

2 Answers2

3

The old app requests has been renamed Game Requests and is limited to games only.

The App Invites dialog was just launched recently, and is for all mobile apps (with iOS or Android native apps). With the app invites dialog, you can set a URL (that's app links enabled), you can also add a picture to the invite. However, you cannot prefill with a message, the user must type that in.

Ming Li
  • 15,672
  • 3
  • 37
  • 35
  • 1
    Do you know how to get the selected friends id with the AppInviteDialog? – Juampa Apr 14 '15 at 23:06
  • You can't. That's by design. – Ming Li Apr 14 '15 at 23:25
  • Yes and it's wrong. Developers should be able to do something else on their end after the Facebook invitations have been sent. For example, I need to create our own invitations, so that I can match the new user with the received invitation. – Juampa Apr 14 '15 at 23:42
  • 2
    You are free to attach tracking IDs to the url that's in the app invite. That's the correct way to track the flow of the invite. – Ming Li Apr 14 '15 at 23:49
2

I got the solution, find below, this is the new implementation of app request dialog in facebook sdk4.

    String appLinkUrl = "https://fb.me/...";
    String previewImageUrl = ...;
    final String TAG = "fbv4";

    if (AccessToken.getCurrentAccessToken() == null) {
        // start login...
    } else {
        FacebookSdk.sdkInitialize(activity.getApplicationContext());
        CallbackManager callbackManager = CallbackManager.Factory.create();

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

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

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

        AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
        if (appInviteDialog.canShow()) {
            AppInviteContent.Builder content = new AppInviteContent.Builder();
            content.setApplinkUrl(appLinkUrl);
            content.setPreviewImageUrl(previewImageUrl);
            AppInviteContent appInviteContent = content.build();
            appInviteDialog.registerCallback(callbackManager, facebookCallback);
            appInviteDialog.show(activity, appInviteContent);
        }
    }
}
Akhilesh Dhar Dubey
  • 2,152
  • 2
  • 25
  • 39
  • I found that for the `FacebookCallback` to receive its callbacks, the `CallbackManager` must be added to `onActivityResult` to handle the result: `callbackManager.onActivityResult(requestCode, resultCode, data);` – n8yn8 Mar 08 '16 at 14:38