更新时间:2023-10-11 22:18:04
要获得好友数量,请参考以下链接:
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
需要的权限是: user_friends
,您已经包括了..
您将在名称中的字段摘要的 total_count
类似的问题: facebook api on android - 如何获得用户拥有的朋友数量?
loginBtn.registerCallback(callbackManager,new FacebookCallback< LoginResult>(){
@Override
public void onSuccess(Login结果loginResult){
new GraphRequest(
loginResult.getAccessToken(),
/ me / friends,
null,
HttpMethod.GET,
new GraphRequest.Callback(){
public void onCompleted(GraphResponse response){
Log.i(response,response.getJSONArray()。toString()); //在响应中找到总结total_count
}
}
).executeAsync();
}
@Override
public void onCancel(){
}
@Override
public void onError(FacebookException exception ){
}
});
I am able to access the id, firstname, lastname, gender, and email of a GraphUser by using the following code.
But, I also need access to "location", "number of friends", "basic info" and "work company". How can this be done? I have tried other *** links, and checked the Facebook SDK link, but not getting a break through. Could I be provided code to directly access the required fields in the same way as the data that I already have?
What other permissions would I need?
loginBtn.setReadPermissions(Arrays.asList("public_profile", "email", "user_friends", "user_birthday", "read_friendlists"));
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
login_text.setText("Please login to continue");
userDetails = new JSONObject();
try {
Log.d("user birthday", user.getBirthday());
userDetails.put("fbId", user.getId());
userDetails.put("firstName", user.getFirstName());
userDetails.put("lastName", user.getLastName());
userDetails.put("gender", user.getProperty("gender").toString());
userDetails.put("email", user.getProperty("email").toString());
} catch (JSONException e) {
Log.d("Error: ", "Error setting user settings in FBActivity");
}
} else {
//login_text.setText("You are not logged");
}
}
});
EDIT:
I got everything except the total number of friends an individual has. How can that be done. I have gone through your links and it seems that I need to call another GraphRequest link. But I don't that. I want the total number of friends (no names, no details, just the number). I have added the permission "user_friends". What code should I write to get the number?
To get number of friends please refer to the following link:
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
Permissions needed would be: user_friends
, which you already have included..
You'll get friends count in field 'summary' in the name of total_count
Similar question: facebook api on android - how can I get the number of friends that a user has?
loginBtn.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
new GraphRequest(
loginResult.getAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i("response", response.getJSONArray().toString()); //find the summary 'total_count' in the response
}
}
).executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
}
});