已安装我的应用程序的 Facebook 好友

Facebook friends that have installed my app

我正在尝试检索已安装我的应用程序的朋友的 ID 列表。我目前正在使用此查询,但它返回了 0 个朋友...这是为什么?

GraphRequest request = GraphRequest.newGraphPathRequest(
                        token,
                        "/"+ facebookUserId +"/friends", response -> {
                            User newUser = new User();

                            if (response.getError() != null) {
                                //TODO: Handle error gracefully
                                Log.e("TEST", response.getError().getErrorMessage());
                                return;
                            }

                            try {
                                JSONArray listOfFriendsJson = response.getJSONObject()
                                        .getJSONArray("data");
                                Log.i("TEST", "Found " + listOfFriendsJson.length() + " friends");

                                for (int i=0 ; i < listOfFriendsJson.length() ; i++) {
                                    JSONObject friendJson = listOfFriendsJson.getJSONObject(i);
                                    newUser.friends_list.put(friendJson.getString("id"), true);
                                    Log.i("TEST", friendJson.getString("id"));
                                }
                            } catch (JSONException e) {
                                Log.e(LOG_TAG, "Error parsing response of GraphRequest", e);
                                //TODO: Stop loading and show error
                            }

                        });

https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#4-4-2018

...Apps requesting the following permissions are now subject to heightened scrutiny during Login Review:

  • ...
  • user_friends
  • ...

我假设 user_friends 权限没有出现在您朋友的登录对话框中。尝试在 App 设置中将您的朋友添加为测试人员,然后再次完成登录过程。确保您在两部手机上都被要求获得 user_friends 权限。