Open varyP opened 9 years ago
auto facebook = cocos2d::plugin::FacebookAgent::getInstance(); std::string permissions = "public_profile,user_friends"; facebook->login(permissions, [=](int ret, std::string& msg){ CCLOG("type is %d, msg is %s", ret, msg.c_str());
if (facebook->isLoggedIn()) { //Save access token auto accessToken = facebook->getAccessToken(); //Save user id auto id = facebook->getUserID(); }
}
ID here after first login comes to be empty.
Fix :
private class SessionStatusCallback implements Session.StatusCallback { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); if(false == isLoggedIn){ if(SessionState.OPENED == state){ isLoggedIn = true; // UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, getSessionMessage(session)); }else if(SessionState.CLOSED_LOGINFAILED == state /|| SessionState.CLOSED == state_/){ UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_FAILED, getErrorMessage(exception, "login failed")); }
} else{ if(SessionState.OPENED_TOKEN_UPDATED == state){ UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, getSessionMessage(session)); } else if(SessionState.CLOSED == state || SessionState.CLOSED_LOGIN_FAILED == state){ isLoggedIn = false; UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_FAILED, getErrorMessage(exception, "failed")); } } } }
private void onSessionStateChange(final Session session, SessionState state, Exception exception) { if (session != null && session.isOpened()) { // make request to the /me API Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { LogD("User here"); if (user != null) { LogD("User here " + user.getId()); userIdStr = user.getId(); UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, getSessionMessage(session)); }
} }).executeAsync(); } }
auto facebook = cocos2d::plugin::FacebookAgent::getInstance();
std::string permissions = "public_profile,user_friends"; facebook->login(permissions, [=](int ret, std::string& msg){ CCLOG("type is %d, msg is %s", ret, msg.c_str());
}
ID here after first login comes to be empty.
Fix :
private class SessionStatusCallback implements Session.StatusCallback { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); if(false == isLoggedIn){ if(SessionState.OPENED == state){ isLoggedIn = true; // UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, getSessionMessage(session));
}else if(SessionState.CLOSED_LOGINFAILED == state /|| SessionState.CLOSED == state_/){
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_FAILED, getErrorMessage(exception, "login failed")); }
private void onSessionStateChange(final Session session, SessionState state, Exception exception) { if (session != null && session.isOpened()) { // make request to the /me API Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { LogD("User here"); if (user != null) { LogD("User here " + user.getId()); userIdStr = user.getId(); UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, getSessionMessage(session)); }