Facebook好友对话框返回“未知方法"错误 [英] Facebook friends dialog returns "Unknown method" error

查看:23
本文介绍了Facebook好友对话框返回“未知方法"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经尝试了很多天了.在任何地方都找不到任何东西.

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

当我尝试使用 Facebook Android SDK 调用好友对话框时,它返回此错误:

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

API 错误代码:3
API 错误描述:未知方法
错误消息:此显示类型不支持此方法

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?

推荐答案

潜在的问题是 Facebook API 尚未为所有显示类型做好准备,并且无法为移动显示显示好友对话框.您可以做的是更改 Facebook android 库:如果您在打开对话框时使用popup"显示模式而不是touch"和 www.facebook.com 而不是 m.facebook.com,一个适当的窗口将出现在Facebook 库标准 WebView.

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.

为此,将 Facebook.java 的对话框功能更改如下:

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

之后,您可能还想从对话框中删除双标题栏.转到 FbDialog.java,并插入类似于 onPageFinished 的内容:

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

这篇关于Facebook好友对话框返回“未知方法"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆