facebook 邀请好友

话不多说,直接上代码了

// 邀请好友
    public void sendFilteredChallenge(final Vector<String> vectFilerFirends, final String strMsg)
    {
        // Get a list of the user's friends' names and devices
        final Session session = Session.getActiveSession();
        Request friendDevicesGraphPathRequest = Request.newGraphPathRequest(
                session, "me/friends", new Request.Callback()
                {
                    @Override
                    public void onCompleted(Response response)
                    {
                        // Hide the progressContainer now that the network call
                        // has completed

                        FacebookRequestError error = response.getError();
                        if (error != null)
                        {

                        } else if (session == Session.getActiveSession())
                        {
                            if (response != null)
                            {
                                // Get the result
                                GraphObject graphObject = response
                                        .getGraphObject();
                                JSONArray dataArray = (JSONArray) graphObject
                                        .getProperty("data");
                                // [{"id":"100000439770527","name":"Yujia Xu"},{"id":"100000504584571","devices":[{"os":"Android"},{"os":"iOS","hardware":"iPhone"}],"name":"Hu Rong"},{"id":"100001195425864","devices":[{"os":"Android"}],"name":"Wu Junzi"},{"id":"100003790094643","name":"Kun  Qiu"}]
                                if (dataArray.length() > 0)
                                {
                                    ArrayList<String> filteredFriendIDs = new ArrayList<String>();

                                    for (int i = 0; i < dataArray.length(); i++)
                                    {
                                        JSONObject currentUser = dataArray
                                                .optJSONObject(i);
                                        if (currentUser != null)
                                        {
                                            String strId = currentUser.optString("id");
                                            boolean bFlag = false;
                                            for(int j=0; j<vectFilerFirends.size(); j++)
                                            {
                                                if(strId.equalsIgnoreCase(vectFilerFirends.get(j)))
                                                {
                                                    bFlag = true;
                                                    break;
                                                }
                                            }
                                            if(!bFlag)
                                            {
                                                filteredFriendIDs.add(currentUser.optString("id"));
                                            }
                                        }
                                    }

                                    Bundle params = new Bundle();
                                    params.putString("message",strMsg);

                                    params.putString(
                                            "suggestions",
                                            TextUtils
                                                    .join(",",
                                                            filteredFriendIDs
                                                                    .toArray(new String[filteredFriendIDs
                                                                            .size()])));

                                    // Show FBDialog without a notification bar
                                    showDialogWithoutNotificationBar(
                                            "apprequests", params);
                                }
                            }
                        }
                    }
                });
        // Pass in the fields as extra parameters, then execute the Request
        Bundle extraParamsBundle = new Bundle();
        extraParamsBundle.putString("fields", "name,devices");
        friendDevicesGraphPathRequest.setParameters(extraParamsBundle);
        Request.executeBatchAsync(friendDevicesGraphPathRequest);
    }


    private void showDialogWithoutNotificationBar(String action, Bundle params)
    {
        // Create the dialog
        WebDialog dialog = new WebDialog.Builder(mstaticContext,
                Session.getActiveSession(), action, params)
                .setOnCompleteListener(new WebDialog.OnCompleteListener()
                {

                    @Override
                    public void onComplete(Bundle values,
                            FacebookException error)
                    {
                        //[{to[0]=100000504584571, request=612136952185524}]
                        if (error != null
                                && !(error instanceof FacebookOperationCanceledException))
                        {
                            // (mstaticContext).showError(mstaticContext.getResources().getString(R.string.network_error),
                            // false);
                        }
                        else
                        {
                            if(values != null)
                            {
                                String strRquestId = (String) values.getCharSequence("request");
                                Vector<String>  vectString = new Vector<String>();
                                int nCount = 0;
                                for(int i=0; i<200; i++)
                                {
                                    String strKey = "to["+i+"]";
                                    String strValue = values.getString(strKey);
                                    if(strValue != null &&!strValue.equalsIgnoreCase(""))
                                    {
                                        vectString.add(strValue);
                                        nCount++;
                                    }
                                    
                                }
                                mfacebookCallback.sendRuquestCallback(vectString, strRquestId);
                            }

                        }
                    }
                }).build();

        // Hide the notification bar and resize to full screen
        Window dialog_window = dialog.getWindow();
        dialog_window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Show the dialog
        dialog.show();
    }



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值