如何在facebook sdk 3.0 Android上发送请求

时间:2013-05-05 04:08:15

标签: android facebook facebook-android-sdk

我在android sdk 3.0上工作,需要向朋友发送请求 我的代码是: -

private void sendRequestDialog(){

    Bundle params = new Bundle();

    params.putString("message",
            "Learn how to make your Android apps social");

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

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

当我点击发送按钮Toast即将发送请求发送但请求不会发送给朋友并且没有通知给那位朋友但是我需要这个我没有得到什么是problum请帮助我;)

3 个答案:

答案 0 :(得分:1)

您需要在Bundle params中添加朋友的脸书ID。

params.putString("to", uid);

答案 1 :(得分:1)

private void sendInviteDialog(String uid,final int position) {
    Bundle params = new Bundle();
    params.putString("to", uid); 
    params.putString("message", "Please try my app"); 
    WebDialog requestsDialog = (
        new WebDialog.RequestsDialogBuilder(getActivity(),
            Session.getActiveSession(),
            params))
            .setOnCompleteListener(new OnCompleteListener() {
                @Override
                public void onComplete(Bundle values,FacebookException error) {
                    if (error != null) {
                        if (error instanceof FacebookOperationCanceledException) {
                            MessageUtil.showMessage( "Request cancelled", true);
                        } else {
                            MessageUtil.showMessage( ResourcesUtil.getString(R.string.network_unavailable), true);
                        }
                    } else {
                        final String requestId = values.getString("request");
                        if (requestId != null) {
                            MessageUtil.showMessage( ResourcesUtil.getString(R.string.friend_request_sent), true);
                        } else {
                            MessageUtil.showMessage(ResourcesUtil.getString(R.string.request_not_successful), true);
                        }
                    }   
                    mProgressDialog.dismiss();
                }

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

答案 2 :(得分:1)

这是因为您的应用处于沙盒模式。禁用沙盒模式。它可以正常工作