0

我已经编写了一个用于在 facebook 上发送 apprequest 的代码示例。

这是我的代码:

Facebook facebook = new Facebook(APP_ID);
Bundle params = new Bundle();
params.putString("title", "Goal Machine");//name
params.putString("message", sendInvite);//link
params.putString("to", Constant.facebookIdBuffer.toString());
params.putString("data", Constant.shortAppUrlForAndroid+"\n"+Constant.shortAppUrlForIphone);
facebook.dialog(_activity, "apprequests", params, new DialogListener() {//send
    @Override
    public void onComplete(Bundle values) {
        Constant.facebookIdBuffer=null;
        postToWall(sendInvite);
    }

    @Override
    public void onFacebookError(FacebookError error) {
        Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
        Constant.facebookIdBuffer=null;
    }

    @Override
    public void onError(DialogError e) {
        Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
        Constant.facebookIdBuffer=null;
    }

    @Override
    public void onCancel() {
        Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
        Constant.facebookIdBuffer=null;
    }
});

但它不断显示错误对话框:

请建议我出了什么问题..? 在此处输入图像描述

4

1 回答 1

0

使用以下代码完成您的任务:-

Bundle params = new Bundle();
params.putString("to", friendId);
params.putString("message", "I am using this app...this is an awesome app" + "\n You should try it.");
params.putString("frictionless", "1");

WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(context, session, params)).setOnCompleteListener(
new OnCompleteListener() {
    @Override
    public void onComplete(Bundle values, FacebookException error) {

         if (error != null) {
            if (error instanceof FacebookOperationCanceledException) {
               Toast.makeText(context, "Request cancelled", Toast.LENGTH_SHORT).show();
            } else {
               Toast.makeText(context, "Network Error", Toast.LENGTH_SHORT).show();                         }
            } else {
               final String requestId = values.getString("request");
                if (requestId != null) {
                    Toast.makeText(context, "Request sent", Toast.LENGTH_SHORT).show();

                final String requestId = values.getString("request");
                if (requestId != null) {
                    Toast.makeText(context, "Request sent: " + requestIdd, Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(context, "Request cancelled", Toast.LENGTH_SHORT).show();

            }
       }
   }
}).build();

requestsDialog.show();
于 2013-09-06T15:29:52.920 回答