我正在开发一个 android 应用程序,我需要在其中使用 Facebook 登录并获取 Facebook 朋友。
我正在使用下面的代码来获取 facebook 朋友:
公共类 FriendsRequestListener 实现 RequestListener {
/**
* Called when the request to get friends has been completed.
* Retrieve and parse and display the JSON stream.
*/
public void onComplete(final String response) {
try {
// process the response here: executed in background thread
Log.d("Facebook-Example-Friends Request", "response.length(): " +
response.length());
Log.d("Facebook-Example-Friends Request", "Response: " + response);
final JSONObject json = new JSONObject(response);
JSONArray d = json.getJSONArray("data");
int l = (d != null ? d.length() : 0);
Log.d("Facebook-Example-Friends Request", "d.length(): " + l);
for (int i=0; i<l; i++) {
JSONObject o = d.getJSONObject(i);
String n = o.getString("name");
String id = o.getString("id");
}
// Only the original owner thread can touch its views
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
}
}
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
调用这个类的方法:
mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/friends", new FriendsRequestListener());
问题是我的代码在调用上述代码时没有做任何事情。