如何向Facebook中的已知用户发送好友请求? (机器人)

时间:2014-09-23 21:53:42

标签: java android facebook facebook-graph-api

我已阅读此https://developers.facebook.com/docs/android/send-requests#notifications教程,而且我不明白如何向Facebook中的已知用户发送好友请求(在Android应用程序中)。我有用户ID。我一直在努力,但我没有成功。

这是我的代码,如果有人有建议我该如何做到这一点会非常有帮助:) 此代码介绍了如何进行APP请求,我想做一个朋友请求。

private void sendRequestDialog() 
{
    Bundle params = new Bundle();
    params.putString("message", "Learn how to make your Android apps social");

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

            }).setTo("XXXXXXXXX").build();

    requestsDialog.show();
}

谢谢你提前:)

0 个答案:

没有答案