2015-05-25 88 views
1

我正在使用facebook SDK 4.0.1。我給了user_friends許可,但我無法獲得用戶的好友列表。我得到的用戶的朋友計數,但我想要的用戶的朋友和IDS名從facebook圖形API中提取用戶朋友列表v2.3

private FacebookCallback<LoginResult> mcallback = new FacebookCallback<LoginResult>() { 
@Override 
public void onSuccess(LoginResult loginResult) { 
accessToken = loginResult.getAccessToken(); 
Log.d("Access Token", accessToken.toString()); 
Profile profile = Profile.getCurrentProfile(); 
// Log.d("PROFILE","PROFILE IMAHE"+profile.getName()); 
displayWelcomeMessage(profile); 

GraphRequestBatch batch = new GraphRequestBatch(
GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() { 
@Override 
public void onCompleted(JSONObject jsonObject, GraphResponse response) { 
try { 
SharedPreferences.Editor editor = prefs.edit(); 
editor.putString(Constant.KEY_ID,jsonObject.getString("id")); 
editor.putString(Constant.KEY_USER_NAME,jsonObject.getString("name")); 
editor.putString(Constant.KEY_USER_FNAME,jsonObject.getString("first_name")); 
editor.putString(Constant.KEY_USER_LNAME,jsonObject.getString("last_name")); 
// hometown = jsonObject.getJSONObject("hometown"); 
// editor.putString(Constant.KEY_USER_HOMETOWN,hometown.getString("name")); 
editor.putString(Constant.KEY_USER_EMAIL,jsonObject.getString("email")); 
editor.putString(Constant.KEY_USER_GENDER,jsonObject.getString("gender")); 
// editor.putString(Constant.KEY_USER_DOB,jsonObject.getString("birthday")); 

editor.commit(); 
// town = hometown.getString("name"); 
// personId = jsonObject.getString("id"); 
// gen = jsonObject.getString("gender"); 
// email = jsonObject.getString("email"); 
Log.d("RESPONCE", "RESPONCE user=" + jsonObject.toString()); 
Log.d("RESPONCE", "RESPONCE =" + response.toString()); 

} 
catch (JSONException e) { 
e.printStackTrace(); 
} 

} 
}), 
GraphRequest.newMyFriendsRequest(accessToken, new GraphRequest.GraphJSONArrayCallback() { 
@Override 
public void onCompleted(JSONArray jsonArray, GraphResponse response) { 
//Lo Application code for users friends 
Log.d("RESPONCE FRIEND", "RESPONCE FRIEND=" + jsonArray.toString()); 
Log.d("RESPONCE FRIEND", "RESPONCE =" + response.toString()); 
response.getJSONArray(); 
} 
})); 
batch.addCallback(new GraphRequestBatch.Callback() { 
@Override 
public void onBatchCompleted(GraphRequestBatch graphRequests) { 
// Application code for when the batch finishes 
} 
}); 
batch.executeAsync(); 
+0

我相信,在最近的API更改後,這是不再允許的。唯一可以看到的朋友是那些也註冊到您的應用的朋友。 –

+0

您也可以使用腳本從用戶的好友列表中刮取數據,儘管這在技術上違背了Facebook的政策。 –

回答