-2
我正在檢索Facebook朋友;你能建議如何從給定的代碼從Facebook中檢索。我是android新手。所以請幫助我做到這一點。我沒有從Facebook SDK獲得正確的指導方針。如何檢索朋友列表中的Facebook朋友?
代碼如下。
好友申請
import java.util.Arrays;
import java.util.List;
import com.facebook.Session;
import com.facebook.Request;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.HttpMethod;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;
import com.facebook.widget.LoginButton;
import com.facebook.widget.LoginButton.UserInfoChangedCallback;
public class MainActivity extends FragmentActivity {
private LoginButton loginBtn;
private UiLifecycleHelper uiHelper;
private ListView friendList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, statusCallback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
friendList = (ListView) findViewById(R.id.friends_list);
loginBtn = (LoginButton) findViewById(R.id.fb_login_button);
loginBtn.setReadPermissions(Arrays.asList("email"));
loginBtn.setReadPermissions(Arrays.asList("user_friends"));
// final Session session = Session.getActiveSession();
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
// new Request(
// Session.getActiveSession(),
// "/me/friends",
// null,
// HttpMethod.GET,
// new Request.Callback() {
// public void onCompleted(Response response) {
// System.out.println("RESPONSE :- " + response.toString());
// Log.i("DJ", "response; " + response.toString());
// }
// }).executeAsync();
} else {
}
}
});
}
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.d("MainActivity", "Facebook session opened.");
} else if (state.isClosed()) {
Log.d("MainActivity", "Facebook session closed.");
}
}
};
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onSaveInstanceState(Bundle savedState) {
super.onSaveInstanceState(savedState);
uiHelper.onSaveInstanceState(savedState);
}
}
我已經做了所有的事情,我有我的fb應用程序ID和釋放密鑰 應用程序ID: - 1547076915541502 – 2015-02-09 06:08:53