简体   繁体   中英

Facebook SDK v3.0 Request Dialog not sending application request

I am using Android SDK v3.0 for Facebook to send requests to friends for using my app. I've used the code I saw on here to open up Facebook's Dialog app and make a request to the user's friends.

After using the following code to display and send the request. I now get a "Request Sent" toast but the request is never sent.

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

The following log is obtained from Logcat during the display of Request Dialog :

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.

Please point me in the right direction...

在此Facebook 开发人员页面上:“用户到用户请求仅适用于Canvas应用程序”

In app setting in facebook developer account add a canvas framework and after that add below code to send app request. if in activity replace getActivity() with YourActivityName.this if in fragment no need to replace anything

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM