facebook - Not being able to authenticate using in Android App -
i have created button in ui on clicking should call function(fblogin()), opens session (if closed) , authorizes user.
public void fblogin(view button) { log.e(getclass().getname(), "0"); settings.addloggingbehavior(loggingbehavior.include_access_tokens); session session = session.getactivesession(); if (session == null) { log.e(getclass().getname(), "1"); if (savedinstancestate != null) { log.e(getclass().getname(), "2"); session = session.restoresession(this, null, statuscallback, savedinstancestate); } if (session == null) { log.e(getclass().getname(), "3"); session = new session(this); } log.e(getclass().getname(), "4"); session.setactivesession(session); if (session.getstate().equals(sessionstate.created_token_loaded)) { log.e(getclass().getname(), "5"); session.openforread(new session.openrequest(this) .setcallback(statuscallback)); } } log.e(getclass().getname(), "6"); updateview(); }
updateview() :
private void updateview() { final session session = session.getactivesession(); if (session.isopened()) { log.e(getclass().getname(), "7"); request.executemerequestasync(session, new request.graphusercallback() { // callback after graph api response user object @override public void oncompleted(graphuser user, response response) { log.e(getclass().getname(), "8"); if (user != null) { string str = user.getname(); intent intent = new intent( getapplicationcontext(), loggedin.class); log.e(getclass().getname(), user.getname()); intent.putextra("username", str); startactivity(intent); } } }); } else { log.e(getclass().getname(), "9"); session.openactivesession(this, true, statuscallback); if(session.isopened()) log.e(getclass().getname(), "15"); log.e(getclass().getname(), "at : "+ session.getaccesstoken()); request.executemerequestasync(session, new request.graphusercallback() { // callback after graph api response user object @override public void oncompleted(graphuser user, response response) { log.e(getclass().getname(), "10"); if(user==null) log.e(getclass().getname(), "11"); if (user != null) { log.e(getclass().getname(), "12"); string str = user.getname(); intent intent = new intent( getapplicationcontext(), loggedin.class); log.e(getclass().getname(), user.getname()); intent.putextra("username", str); startactivity(intent); } } }); } }
my sessionstatuscallback class:
private class sessionstatuscallback implements session.statuscallback { @override public void call(session session, sessionstate state, exception exception) { log.e(getclass().getname(), session.getstate().tostring()); log.e(getclass().getname(), "13"); // updateview(); } }
in sessionstatuscallback class shows session state first opening , closed_login_failed. why the state changing closed_login_failed.
logcat output:
08-12 17:56:31.928: e/com.example.usemeone.usemeone(966): 0 08-12 17:56:31.948: e/com.example.usemeone.usemeone(966): 1 08-12 17:56:31.948: e/com.example.usemeone.usemeone(966): 3 08-12 17:56:31.988: e/com.example.usemeone.usemeone(966): 4 08-12 17:56:31.998: e/com.example.usemeone.usemeone(966): 6 08-12 17:56:31.998: e/com.example.usemeone.usemeone(966): 9 08-12 17:56:32.157: e/com.example.usemeone.usemeone(966): @ : 08-12 17:56:32.398: e/com.example.usemeone.usemeone$2(966): 10 08-12 17:56:32.408: e/com.example.usemeone.usemeone$2(966): 11 08-12 17:56:32.408: e/com.example.usemeone.usemeone$sessionstatuscallback(966): opening 08-12 17:56:32.408: e/com.example.usemeone.usemeone$sessionstatuscallback(966): 13 08-12 17:57:26.468: e/com.example.usemeone.usemeone$sessionstatuscallback(966): closed_login_failed 08-12 17:57:26.468: e/com.example.usemeone.usemeone$sessionstatuscallback(966): 13
its asks user if wants allow app access his/her facebook profile, after authorizing app changes session state closed_login_failed.
Comments
Post a Comment