是否可以通过Android Facebook SDK 3.0发送好友请求?

时间:2013-02-06 04:10:02

标签: java android facebook sdk dialog

我正在尝试从Android SDK for Facebook发送好友请求。我有机会问一位Facebook工程师,他说Android目前不支持朋友请求。所以我认为我被困在将用户重定向到浏览器。我的问题是我该怎么做?到目前为止这是我的代码:(它不起作用)

private void sendRequestDialog()
{
String USER_ID = "stack.overflow.123";

Bundle params = new Bundle();

params.putString("id", USER_ID);

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

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

1 个答案:

答案 0 :(得分:2)

在您的活动中添加WebView,然后

webView.loadUrl("http://www.facebook.com/dialog/friends/?"+
  "id=brent&"+
  "app_id=123050457758183&"+
  "redirect_uri=https://www.facebook.com/connect/login_success.html");