如何找到与facebook sdk使用相同应用程序的朋友?

时间:2015-05-19 02:17:31

标签: ios swift parse-platform facebook-sdk-4.0

我正在制作一个允许用户使用Facebook注册的应用程序。我正在使用最新的facebook sdk并解析后端。我需要的是,如何找到使用相同应用程序的当前用户的朋友?

1 个答案:

答案 0 :(得分:0)

这是Java代码。如果你没有使用java,请在你的平台上做同等的事情:

@Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                FacebookSdk.sdkInitialize(this.getApplicationContext());
                callbackManager = CallbackManager.Factory.create();
            }

        protected void doFBLoginForProfile() {
        LoginManager loginManager = LoginManager.getInstance();
        loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                getFriends();
            }

            @Override
            public void onCancel() {
            }

            @Override
            public void onError(FacebookException error) {

            }
        });
        loginManager.logInWithReadPermissions(this, getReadPermissions());
    }

        private ArrayList<String> getReadPermissions() {
                ArrayList<String> fbPermissions = new ArrayList<String>();
                fbPermissions.add("public_profile");
                fbPermissions.add("email");
                fbPermissions.add("user_location");
                fbPermissions.add("user_friends");
                return fbPermissions;
            }


        private void getFriends() {
                onShowFbProgress();
                if (hasGetFriendListPermission()) {
                    try {
                        GraphRequest.newMyFriendsRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONArrayCallback() {
                            @Override
                            public void onCompleted(JSONArray objects, GraphResponse response) {
                                Utils.displayLogs("FB", "FRIENDS LISTS " + objects);
                            }
                        }).executeAsync();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                }
            }

    public boolean hasGetFriendListPermission() {
            return AccessToken.getCurrentAccessToken().getPermissions().contains("user_friends");
        }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }