Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Android getUserId on first login. #160

Open
varyP opened this issue Jun 1, 2015 · 0 comments
Open

Issue with Android getUserId on first login. #160

varyP opened this issue Jun 1, 2015 · 0 comments

Comments

@varyP
Copy link

varyP commented Jun 1, 2015

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_LOGIN_FAILED == 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();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant