Reputation: 593
I am unable to get the complete user profile using the Facebook sdk. I am trying to retrieve the user node from the Facebook's graph API referring to the following link. I am only receiving a few fields(sort of a limited profile thingy)
https://developers.facebook.com/docs/graph-api/reference/user
I first perform login using the following line.
LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("public_profile", "user_friends"));
Once I have an access token, I call the "/me" endpoint. I get the Facebook user ID of the respective user. Using this ID, I then call the "/{user-id}" endpoint using the following bit of code.
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + userProfile.getId(),
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.d(TAG, response.getRawResponse());
}
}
).executeAsync();
The fields returned however are limited and do not contain the complete set of fields mentioned in the link below.
https://developers.facebook.com/docs/graph-api/reference/user
How do i retrieve the complete set of data tied to a user, including the list of friends , age etc as mentioned in the above link?
I am only able to retrieve id,email ,first_name,gender,last_name,link,locale,name, timezone and verified fields, currently.
Upvotes: 2
Views: 930
Reputation: 593
I figured out how to retrieve the required or specific fields. By default all fields from a particular node are not returned. You need to specify them by passing them as parameters as shown below.
GraphRequest graphRequest = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.d(TAG, response.getRawResponse());
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,email,first_name,gender,last_name,link,locale,name,timezone,updated_time,verified,age_range,friends");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
Upvotes: 1