简体   繁体   English

如何在Facebook SDK 3.0 Android上发送请求

[英]How to send request on facebook sdk 3.0 Android

i am working on facebook sdk 3.0 in android and need to send request to friends and my code is :- 我正在使用Android上的facebook sdk 3.0,需要将请求发送给朋友,而我的代码是:-

private void sendRequestDialog() { 私人无效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();
}

when i am clicking on Send button Toast is coming for request send but request is not coming to friends and no notification coming to that friend but i need this i am no getting what is problum please help me;) 当我单击“ 发送”按钮时,Toast即将发送请求,但是请求没有发送给朋友 ,也没有通知发送给该朋友,但是我需要这个,但我没有得到什么问题,请帮助我;)

您需要在Bundle参数中添加您朋友的Facebook ID。

params.putString("to", uid);

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

那是因为您的应用程序处于沙盒模式,请禁用沙盒模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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