私はのように使用しています
public class FbFriendsActivity extends WebCallableCoreActivity {
private ListView list;
private Button btnDone;
private FbFriendsAdapter adapter;
private int index = -1;
View view_loading;
private ArrayList<FbData> mlist;
private Session.StatusCallback statusCallback = new SessionStatusCallback();
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
view_loading.setVisibility(View.VISIBLE);
execQuery();
} else if (state.equals(SessionState.CLOSED_LOGIN_FAILED)) {
view_loading.setVisibility(View.GONE);
Toast.makeText(FbFriendsActivity.this, "Facebook Login fail",
Toast.LENGTH_LONG).show();
} else if (state.equals(SessionState.OPENING)) {
view_loading.setVisibility(View.VISIBLE);
}
}
}
private void onClickLogin() {
Session session = Session.getActiveSession();
if (session == null) {
session = new Session(this);
Session.setActiveSession(session);
}
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this)
.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK)
.setCallback(statusCallback)
.setPermissions(
Arrays.asList("basic_info", "user_about_me",
"email")));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
public void execQuery() {
String fqlQuery = "SELECT uid, name, pic_square FROM user WHERE uid IN "
+ "(SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 200)";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session, "/fql", params, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
view_loading.setVisibility(View.GONE);
Log.i("Friends", "Result: " + response.toString());
try {
GraphObject go = response.getGraphObject();
JSONObject jso = go.getInnerJSONObject();
JSONArray arr = jso.getJSONArray("data");
mlist.clear();
FbData data;
for (int i = 0; i < (arr.length()); i++) {
JSONObject json_obj = arr.getJSONObject(i);
data = new FbData();
data.setName(json_obj
.getString(ParsingTagConst.FB_NAME));
data.setFbId(json_obj
.getString(ParsingTagConst.FB_ID));
data.setImageUrl(json_obj
.getString(ParsingTagConst.FB_IMAGE_URL));
boolean isAppUser = json_obj
.getBoolean(ParsingTagConst.FB_IS_APP_USER);
if (isAppUser) {
mlist.add(data);
}
data = null;
}
adapter.notifyDataSetChanged();
} catch (Throwable t) {
t.printStackTrace();
}
}
});
Request.executeBatchAsync(request);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fb_riends);
list = (ListView) findViewById(R.id.list);
btnDone = (Button) findViewById(R.id.btn_done);
view_loading = (View) findViewById(R.id.layout_loading);
mlist = new ArrayList<FbData>();
adapter = new FbFriendsAdapter(this, mlist);
list.setAdapter(adapter);
checkInternet();
btnDone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (mlist.size() > 0) {
String fbId = mlist.get(index).getFbId();
makeWebRequest(FbFriendsActivity.this,
UrlConst.GAME_WITH_FB_USER_URL,
IdConst.GAME_WITH_FB_ID, true, WebRequestHelper
.createGameWithFbRequest(AppPreferences
.getInstance().getUserId(), fbId));
} else {
Toast.makeText(FbFriendsActivity.this,
"No Imtemt Selected", Toast.LENGTH_LONG).show();
}
}
});
if (ApplicationClass.isConnected) {
// makeWebRequest(FbFriendsActivity.this,
// UrlConst.RANDOM_APPONENT_URL, IdConst.RANDOM_APPONENT,
// true, null);
onClickLogin();
} else {
Toast.makeText(FbFriendsActivity.this, "No Internet ",
Toast.LENGTH_LONG).show();
}
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
index = arg2;
}
});
}
public void Cancel(View v) {
FbFriendsActivity.this.finish();
}
@Override
protected void useResponseData(JSONObject result, String identifier) {
// TODO Auto-generated method stub
if (result != null) {
// {"CommandResult":{"response_string":"User not found","success":"0"}}
try {
JSONObject jsonObject = result
.getJSONObject(ParsingTagConst.COMMANDRESULT);
String strSuccess = jsonObject
.getString(ParsingTagConst.SUCCESS);
if (strSuccess.equals("1")) {
Intent intent = new Intent(FbFriendsActivity.this,
GameOfSkateActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
Toast.makeText(FbFriendsActivity.this,
"Your friend has not install SKATE",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
public void checkInternet() {
WaitForInternetCallback callback = new WaitForInternetCallback(this) {
public void onConnectionSuccess() {
ApplicationClass.isConnected = true;
}
public void onConnectionFailure() {
ApplicationClass.isConnected = false;
}
};
try {
WaitForInternet.setCallback(callback);
} catch (SecurityException e) {
callback.onConnectionSuccess();
}
}
}