0

So I have been trying this since many days. Could not find anything anywhere.

When I try to call the Friends dialog with Facebook Android SDK it return this error:

API Error Code: 3
API Error Description: Unknown method
Error Message: This method isn't supported for this display type

I didn't find anything on documentation pages telling that friends dialog is not allowed on touch devices. I am using the following code to do this:

Bundle params = new Bundle();
params.putString("id", "brent");
Log.i("In on click", params.toString());
SampleDialogListener());
mFacebook.dialog(TestActivity.this, "friends", params, new SampleDialogListener());

If it's not allowed is there any alternative way to send a friend request from within an application?

Vashishtha Jogi
  • 12,120
  • 2
  • 19
  • 20

3 Answers3

6

The underlying problem is that the Facebook API is not yet ready for all the display types, and the friends dialog cannot be shown for the mobile display. What you can do is to change the Facebook android library: if you use "popup" display mode instead of "touch" and www.facebook.com instead of m.facebook.com while opening the dialog, a proper window will appear in the Facebook librarys standard WebView.

For this, change the dialog function of Facebook.java as follows:

protected static String DIALOG_BASE_URL = "https://m.facebook.com/dialog/";
protected static String DIALOG_BASE_URL_FOR_MISSING_SCREENS = "https://www.facebook.com/dialog/";

public void dialog(Context context, String action, Bundle parameters,
        final DialogListener listener) {

    boolean missingScreen = action.contentEquals("friends") ? true : false;

    String endpoint = missingScreen ? DIALOG_BASE_URL_FOR_MISSING_SCREENS : DIALOG_BASE_URL;
    endpoint += action;

    parameters.putString("display", missingScreen ? "popup" : "touch");
    parameters.putString("redirect_uri", REDIRECT_URI);

    if (action.equals(LOGIN)) {
        parameters.putString("type", "user_agent");
        parameters.putString("client_id", mAppId);
    } else {
        parameters.putString("app_id", mAppId);
    }

    if (isSessionValid()) {
        parameters.putString(TOKEN, getAccessToken());
    }
    String url = endpoint + "?" + Util.encodeUrl(parameters);
    if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
            != PackageManager.PERMISSION_GRANTED) {
        Util.showAlert(context, "Error",
                "Application requires permission to access the Internet");
    } else {
        new FbDialog(context, url, listener).show();
    }
}

After that you might want to remove the double title bar from the dialog as well. Go to FbDialog.java, and insert something similar to onPageFinished:

if (url.contains("friends?")) {
    mTitle.setHeight(0);
    mTitle.setVisibility(View.INVISIBLE);
}
Wimagguc
  • 1,001
  • 1
  • 7
  • 12
  • Tx for the info. For my iOS app, I have a pb because I'm using the fb:// scheme for the authentication and not the web page login. When I call the dialog for the friend request, the dialog appears but I have a message for authentication... How to avoid this authentication screen (because I'm already authenticated and I have the token) ? – fvisticot Dec 14 '11 at 23:29
2

Works.

class Facebook_friendsPatch extends Facebook { 
   protected static String DIALOG_BASE_URL = "https://m.facebook.com/dialog/";
   protected static String DIALOG_BASE_URL_FOR_MISSING_SCREENS = "https://www.facebook.com/dialog/";
   protected static final String LOGIN = "oauth"; 
   protected String appId ; 

   public Facebook_friendsPatch(String app) {    
      super(app) ; 
      appId = app ; 
   }

   public void dialog(Context context, String action, Bundle parameters,
                      final DialogListener listener) {
      // copy from above 
   } 
}
vpathak
  • 1,133
  • 12
  • 12
0

This tutorial has an example of using a dialog in the facebook API:

dave.c
  • 10,910
  • 5
  • 39
  • 62
  • Yes. I have seen that. But it does not tell anything about friend request. I tried using this code, but it gives me same error. – Vashishtha Jogi Mar 21 '11 at 18:56
  • @Vashishtha Jogi Well, the code you have supplied above won't actually compile, so I can't compare it with the code in the tutorial. For example the line `SampleDialogListener());` seems to have a syntax error. Perhaps you can edit your original post to supply your current code, and also provide your implementation of `SampleDialogListener()`. – dave.c Mar 21 '11 at 19:31
  • http://code.google.com/p/ubinfc/source/browse/#svn%2Ftrunk I have all my source code uploaded here. – Vashishtha Jogi Mar 22 '11 at 05:44
  • @Vashishtha Jogi In the tutorial, `MyDialogListener extends com.facebook.android.Facebook.DialogListener`, and in your code `SampleDialogListener extends BaseDialogListener`. I would try the way the tutorial does it and see what happens. – dave.c Mar 22 '11 at 08:27