Facebook SDK v3.0请求对话框不发送应用程序请求

时间:2013-03-15 12:39:23

标签: android facebook

我正在使用Android SDK v3.0 for Facebook向朋友发送使用我的应用的请求。我已经使用我在here上看到的代码打开Facebook的Dialog应用程序并向用户的朋友发出请求。

使用以下代码显示并发送请求后。我现在收到“请求已发送”的吐司,但请求永远不会被发送。

private void sendRequestDialog() {
    Bundle params = new Bundle();
    params.putString("message", "MESSAGE");
    params.putString("app_id", "APPID");

    WebDialog requestsDialog = (
        new WebDialog.RequestsDialogBuilder(LoginActivity.this,
            Session.getActiveSession(),
            params))
            .setOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(Bundle values,
                    FacebookException error) {
                    if (error != null) {
                        if (error instanceof FacebookException) {
                            Toast.makeText(LoginActivity.this.getApplicationContext(), 
                                "Request cancelled", 
                                Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(LoginActivity.this.getApplicationContext(), 
                                "Network Error", 
                                Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        final String requestId = values.getString("request");
                        if (requestId != null) {
                            Toast.makeText(LoginActivity.this.getApplicationContext(), 
                                "Request sent",  
                                Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(LoginActivity.this.getApplicationContext(), 
                                "Request cancelled", 
                                Toast.LENGTH_SHORT).show();
                        }
                    }   
                }

            })
            .build();
    requestsDialog.show();
}

在显示请求对话框期间从Logcat获取以下日志:

03-15 17:18:51.944: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:18:53.759: V/chromium(2842): external/chromium/net/base/bandwidth_metrics.h:96: [0315/171853:INFO:bandwidth_metrics.h(96)] Bandwidth: 1500.13Kbps (avg 2275.13Kbps)
03-15 17:18:54.124: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:18:58.019: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:18:58.629: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:18:58.684: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:18:59.314: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:18:59.369: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:18:59.949: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:18:59.954: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:19:00.534: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:19:00.539: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:19:01.329: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:19:03.459: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:19:03.984: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:19:04.019: W/dalvikvm(2842): disableGcForExternalAlloc: true
03-15 17:19:04.189: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:19:06.269: W/dalvikvm(2842): disableGcForExternalAlloc: false
03-15 17:19:10.869: I/NONPRIME(2842): <CallBackProxy> Send to WebViewClient.

请指出正确的方向......

2 个答案:

答案 0 :(得分:2)

从这个Facebook developers页面: “用户到用户请求仅适用于Canvas应用程序”

答案 1 :(得分:0)

在Facebook开发者帐户的应用设置中添加画布框架,然后添加以下代码以发送应用请求。 if in activity用YourActivityName.this替换getActivity() 如果在片段中不需要替换任何东西

Bundle params = new Bundle();
            params.putString("message",
                    "Join CConnect To feel Better Experience Of Meetings And Calls");

            WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
                    getActivity(), Session.getActiveSession(), params))
                    .setTheme(
                            android.R.style.Theme_Translucent_NoTitleBar_Fullscreen))
                    .setOnCompleteListener(new OnCompleteListener() {

                        @Override
                        public void onComplete(Bundle values,
                                FacebookException error) {
                            if (error != null) {
                                if (error instanceof FacebookOperationCanceledException) {
                                    Toast.makeText(
                                            getActivity()
                                                    .getApplicationContext(),
                                            "Request cancelled",
                                            Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(
                                            getActivity()
                                                    .getApplicationContext(),
                                            "Network Error", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            } else {
                                final String requestId = values
                                        .getString("request");
                                if (requestId != null) {
                                    Toast.makeText(
                                            getActivity()
                                                    .getApplicationContext(),
                                            "Request sent", Toast.LENGTH_SHORT)
                                            .show();
                                } else {
                                    Toast.makeText(
                                            getActivity()
                                                    .getApplicationContext(),
                                            "Request cancelled",
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        }

                    }).build();
            requestsDialog.show();