Facebook friends dialog returns "Unknown method" error
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?
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);
}
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
}
}