My goal is to get information about facebook users. In particular, gender, date of birth, full name, place of study. I received the so-called "User Access Marker", now, in theory, I can make requests and receive information, but no, the data is empty for some reason .. except for id, id.

I see "Login Verification", but I just can not understand how it relates to my tasks. I do not want to create a public application that will have an audience or something like this ..

The question is, I need to delve into it, and if so, what do they need to provide ...?

  • And what permissions did you request when you received the access token? - Kirill Stoianov
  • You did not request any additional permissions, do you want to say that when you receive a token, you need to request permissions in the request itself? As I understand it, permissions are needed for the application .. - user2572457
  • Yes, I added the answer, maybe you just did not indicate the fields you are interested in when receiving the token - Kirill Stoianov
  • I do not quite understand, I need a token user or application. Can you explain this? - user2572457
  • You need a user token, I updated the answer! - Kirill Stoianov

1 answer 1

The following lines should be written in Manifest.xml

<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id" /> 

If you get a token in this way, then you need to specify the fields of your own type as public_profile list of these permissions can be found in the documentation. When receiving a user's token, you specify fields together with the request: public_profile , user_friends , etc.

  public void callLoginActivity() { LoginManager loginManager = LoginManager.getInstance(); loginManager.setLoginBehavior(LoginBehavior.NATIVE_WITH_FALLBACK); loginManager.logInWithReadPermissions( activity, Arrays.asList("public_profile", "user_friends", "read_custom_friendlists")); } 

after you have logged in and received a token, you can make requests for obtaining, for example, a list of friends, in order to receive these same friends, you must have permission to receive them, here is an example of such a request:

 public void getFriendsList() { AccessToken token = AccessToken.getCurrentAccessToken(); String userId = token.getUserId(); String path = "/friends"; new GraphRequest(token, userId + path, null, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ JSONArray data; ArrayList <FacebookUser> resultList = new ArrayList <FacebookUser> (); if (response.getError() == null) { try { //get data json object from response data = response.getJSONObject().getJSONArray("data"); //loop data for get list of friends for (int i = 0; i < data.length(); i++) { //get friend from array JSONObject object = (JSONObject) data.get(i); String name = object.getString("name"); long id = object.optLong("id", -1); //put user data to model and save to result list FacebookUser user = new FacebookUser(); user.setName(name); user.setId(id); resultList.add(user); } } catch (JSONException e) { e.printStackTrace(); } } Log.wtf(TAG, "Response error: " + response.getError()); Log.wtf(TAG, "Raw: " + response.getRawResponse()); } } ).executeAsync(); 

For a specific request, you need permissions: "user_friends", "read_custom_friendlists". Those. if you need some other info about the user, you need to request it when you receive the token.