Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...