我使用以下代码将facebook朋友拉进我的Android应用程序。当我调试它显示正确数量的朋友但它无法拉动那些登录到应用程序的朋友。结果是最终的结果是空的。
任何人都可以查看我的代码并告诉我,如果我遗漏了任何内容吗?我注意到变量数据总是空的,但朋友的总数是正确的。
{Response: responseCode: 200, graphObject: {"data":[],"summary":{"total_count":166}}, error: null}
responseObject = {"data":[],"summary":{"total_count":166}}
这是我的代码..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends_list);
final List<String> friendslist2 = new ArrayList<String>();
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/friends", null, HttpMethod.GET, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e(TAG, response.toString());
try {
JSONObject responseObject = response.getJSONObject();
JSONArray dataArray = responseObject.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
JSONObject dataObject = dataArray.getJSONObject(i);
String fbId = dataObject.getString("id");
String fbName = dataObject.getString("name");
Log.e("FbId", fbId);
Log.e("FbName", fbName);
friendslist2.add(fbId);
}
Log.e("fbfriendList_data", friendslist2.toString());
List<String> list = friendslist2;
String friends = "";
if (list != null && list.size() > 0) {
friends = list.toString();
if (friends.contains("[")) {
friends = (friends.substring(1, friends.length() - 1));
}
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
}
}
}).executeAsync();
`
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, friendslist2); // simple textview for list item
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
}
}
以下活动调用上述代码 - &gt;`
login_button.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult login_result) {
GraphRequestAsyncTask graphRequestAsyncTask = new GraphRequest(
login_result.getAccessToken(),
//AccessToken.getCurrentAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Intent intent = new Intent(MainActivity.this,FriendsList.class);
try {
JSONArray rawName = response.getJSONObject().getJSONArray("data");
intent.putExtra("jsondata", rawName.toString());
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
}
此处还有数据&#39; rawName中的内容为空,但它具有正确的朋友数。
请注意,我朋友列表中有一个人使用Facebook凭据登录应用程序,因此我希望我的应用程序中有该人的详细信息。我已经在主要类别游戏
下使用https://developers.facebook.com/apps注册了该应用非常感谢任何人的帮助。谢谢!
萨蒂亚