简体   繁体   English

Facebook的朋友列表图检索空数组

[英]facebook friend list graph retrive empty array

I have logged in to facebook via the login button, i can get info on myself but from some reason when i try to get the friend list i get an empty json array in return. 我已经通过登录按钮登录到Facebook,我可以获取有关自己的信息,但是由于某些原因,当我尝试获取朋友列表时,会得到一个空的json数组作为回报。 here is the sample code: (i call the graph request on the on success method of my facebook callback private class) 这是示例代码:(我在我的Facebook回调私有类的on success方法上调用了图请求)

private CallbackManager callbackManager;

private FacebookCallback <LoginResult> mCallBack = new FacebookCallback <LoginResult> () {
  @Override
  public void onSuccess(LoginResult loginResult) {

    //some code

    GraphRequest request = GraphRequest.newMyFriendsRequest(
      AccessToken.getCurrentAccessToken(),
      new GraphRequest.GraphJSONArrayCallback() {
        @Override
        public void onCompleted(JSONArray array, GraphResponse response) {
          if (response != null) {
            Log.d("FB", "response isnt null");
          }

          if (array != null) {
            Log.d("FB", "array: " + array.toString());
          }
        }
      });

    Bundle parameters = new Bundle();
    parameters.putString("fields", "first_name,last_name,name,id");
    request.setParameters(parameters);
    request.executeAsync();
    Log.d("FB", "parameters: " + parameters.toString());


  }

  @Override
  public void onCancel() {
    statusText.setText("you have to connect");
  }

  @Override
  public void onError(FacebookException e) {

  }
};

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
  callbackManager = CallbackManager.Factory.create();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
  Bundle savedInstanceState) {
  return inflater.inflate(R.layout.fragment_main, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  statusText = (TextView) view.findViewById(R.id.status_text);
  loginButton = (LoginButton) view.findViewById(R.id.login_button);
  loginButton.setReadPermissions("user_friends");
  loginButton.setFragment(this);
  loginButton.registerCallback(callbackManager, mCallBack);
}

i tried both of this since the facebook graph query shows the id regardless me not asking him: 我尝试了这两种方法,因为无论我是否不问他,facebook图形查询都显示了id:

parameters.putString("fields", "first_name,last_name,name,id");
parameters.putString("fields", "first_name,last_name,name");

Did I miss something? 我错过了什么?


Answer: I have come to know that the graph api 2.0 and above doesn't show all your firends list, instead it will just show you the friends that installed your app and have connected to their FB account from your app, that is if you released your app to the play store. 答:我知道图api 2.0及更高版本并未显示您的所有好友列表,而是仅向您显示安装了您的应用程序并已从您的应用程序连接到他们的FB帐户的朋友。已将您的应用发布到Play商店。 If your app is still under development and hasn't released yet you won't be able to see any friends unless you added them as "testers" and you/they installed the app on a phone/emulator and logged in from their account. 如果您的应用仍在开发中并且尚未发布,那么您将无法看到任何朋友,除非您将其添加为“测试人员”,并且您/他们将其安装在手机/仿真器上并通过其帐户登录。

to add someone as a tester just go to facebook developers, and then: click on "my apps" at the top toolbar -> choose your app from the list -> click on "roles" on the left panel -> click on the "add testers" button -> pick your friends you want to add as testers. 要将某人添加为测试人员,只需转到Facebook开发人员,然后:单击顶部工具栏上的“我的应用”->从列表中选择您的应用->单击左侧面板上的“角色”->单击“添加测试人员”按钮->选择要添加为测试人员的朋友。

FB docs on user_friends permissions says: 关于user_friends权限的FB文档说:

In order for a person to show up in one person's friend list, both people must have decided to share their list of friends with your app and not disabled that permission during login. 为了使一个人出现在一个人的朋友列表中, 两个人都必须决定与您的应用共享他们的朋友列表,并且在登录时未禁用该权限。 Also both friends must have been asked for user_friends during the login process. 同样,必须在登录过程中要求两个朋友都提供user_friends。

Are you sure that some of your friends have logged into your app too? 您确定您的一些朋友也已登录您的应用程序吗?


To see if the request is done correctly regardless of your code, you can use Graph API explorer . 要查看无论代码如何,请求是否都正确完成,可以使用Graph API Explorer Make sure to select your app in top right corner select box, paste access token you get from your app (most likely AccessToken.getCurrentAccessToken() ) and try to make request to /me/friends . 确保在右上角的选择框中选择您的应用,粘贴从应用中获取的访问令牌(很可能是AccessToken.getCurrentAccessToken() ),然后尝试向/me/friends发出请求。 If the request in Graph API explorer returns some data, there is probably something wrong with your code. 如果Graph API Explorer中的请求返回了一些数据,则您的代码可能存在问题。 Otherwise it's some Facebook mechanism, like the one quoted above. 否则,这是某种Facebook机制,例如上面引用的那种。

I have come to know that the graph api 2.0 and above doesn't show all your firends list, instead it will just show you the friends that installed your app and have connected to their FB account from your app, that is if you released your app to the play store. 我知道图api 2.0及更高版本不会显示您的所有朋友列表,而是仅向您显示安装了应用程序并已从您的应用程序连接到其FB帐户的朋友。应用程式前往Play商店。 If your app is still under development and hasn't released yet you won't be able to see any friends unless you added them as "testers" and you/they installed the app on a phone/emulator and logged in from their account. 如果您的应用仍在开发中并且尚未发布,那么您将无法看到任何朋友,除非您将其添加为“测试人员”,并且您/他们将其安装在手机/仿真器上并通过其帐户登录。

to add someone as a tester just go to facebook developers, and then: click on "my apps" at the top toolbar -> choose your app from the list -> click on "roles" on the left panel -> click on the "add testers" button -> pick your friends you want to add as testers. 要将某人添加为测试人员,只需转到Facebook开发人员,然后:单击顶部工具栏上的“我的应用”->从列表中选择您的应用->单击左侧面板上的“角色”->单击“添加测试人员”按钮->选择要添加为测试人员的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM