Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the new implementation of app requests dialog in Android Facebook SDK 4.0.1

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?

like image 258
Akhilesh Dhar Dubey Avatar asked Apr 10 '15 14:04

Akhilesh Dhar Dubey


People also ask

How did you integrate the Facebook SDK in Android app?

To use the Facebook SDK in an Android Studio project, add the SDK as a build dependency and import the SDK. Go to Android Studio | New Project | Minimum SDK. Select API 15: Android 4.0.

What is the purpose of Facebook SDK?

The Facebook SDK for Android gives you access to the following features: Facebook Login — A secure and convenient way for people to log into your app or website by using their Facebook credentials. Sharing — Enable people to post to Facebook from your app. People can share, send a message, and share to stories.

How do I update my Facebook SDK?

Select the App you want to upgrade (you might have access to multiple apps) Click Settings > Advanced. Select the latest version under the Upgrade API Version section for both “Upgrade All Calls” and “Upgrade Calls for App Roles” Save.

How do I set up Facebook SDK?

Configure Your Facebook App for Android First, log into Facebook developer account and do the following: Go to the App Dashboard; Click My Apps and create a new app; Go to Settings > Basic to see the App Details Panel with your App ID, App Secret as well as other app details.


2 Answers

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.

like image 111
Ming Li Avatar answered Sep 21 '22 15:09

Ming Li


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);
        }
    }
}
like image 44
Akhilesh Dhar Dubey Avatar answered Sep 21 '22 15:09

Akhilesh Dhar Dubey