Facebook 好友对话框返回“未知方法”错误

发布于 2024-10-24 02:10:45 字数 510 浏览 3 评论 0原文

所以很多天以来我一直在尝试这个。到处都找不到任何东西。

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

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

我在文档页面上没有找到任何内容告诉触摸设备上不允许朋友对话框。我使用以下代码来执行此操作:

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

如果不允许,是否有其他方法可以从应用程序内发送好友请求?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凌乱心跳 2024-10-31 02:10:45

根本问题是 Facebook API 尚未准备好支持所有显示类型,并且无法为移动显示显示好友对话框。您可以做的是更改 Facebook android 库:如果您在打开对话框时使用“popup”显示模式而不是“touch”,并且使用 www.facebook.com 而不是 m.facebook.com,则在对话框中会出现一个正确的窗口。 Facebook 库标准 WebView。

为此,请按如下所示更改 Facebook.java 的对话框函数:

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 的内容:

if (url.contains("friends?")) {
    mTitle.setHeight(0);
    mTitle.setVisibility(View.INVISIBLE);
}

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);
}
︶ ̄淡然 2024-10-31 02:10:45

作品。

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

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 
   } 
}
一梦等七年七年为一梦 2024-10-31 02:10:45

本教程有一个在 facebook API 中使用对话框的示例:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文