Android facebook login callback not happening -
i'm trying implement facebook login android app using facebook sdk 4.1.0. loginbutton placed inside splashactivity , upon successful login should start mainactivity. however, facebook callback method not runnning @ me , can't figure out causing this.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); facebooksdk.sdkinitialize(this.getapplicationcontext()); setcontentview(r.layout.activity_splash); callbackmanager = callbackmanager.factory.create(); cache = new diskbasedcache(getapplicationcontext().getcachedir(), 1024 * 1024); network = new basicnetwork(new hurlstack()); mrequestqueue = new requestqueue(cache, network); getuserinfo(); skip = (button) findviewbyid(r.id.btnskip); skip.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent done = new intent(getbasecontext(),mainactivity.class); startactivity(done); finish(); } }); loginbutton = (loginbutton) findviewbyid(r.id.login_button); loginbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // call private method onfblogin(); loginbutton.post(new runnable() { @override public void run() { loginbutton.setvisibility(view.invisible); } }); } }); accesstokentracker = new accesstokentracker() { @override protected void oncurrentaccesstokenchanged(accesstoken oldaccesstoken, accesstoken newaccesstoken) { if(newaccesstoken == null){ loginmanager.getinstance().logout(); } } }; accesstoken accesstoken = accesstoken.getcurrentaccesstoken(); if(accesstoken != null){ skip.setvisibility(view.invisible); intent done = new intent(this,mainactivity.class); startactivity(done); finish(); } profiletracker profiletracker = new profiletracker() { @override protected void oncurrentprofilechanged(profile oldprofile, profile newprofile) { } }; accesstokentracker.starttracking(); } private void onfblogin() { // set permissions loginmanager.getinstance().loginwithreadpermissions(this, arrays.aslist("email", "public_profile")); loginmanager.getinstance().registercallback(callbackmanager, new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { accesstoken token = loginresult.getaccesstoken(); // set denied = loginresult.getrecentlydeniedpermissions(); // loginresult.getrecentlygrantedpermissions(); system.out.println("success"); graphrequest.newmerequest( loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() { @override public void oncompleted(jsonobject jsonobject, graphresponse graphresponse) { if (graphresponse.geterror() != null) { // handle error system.out.println("error"); } else { try { mrequestqueue.start(); string jsonresult = string.valueof(jsonobject); system.out.println("json result" + jsonresult); jsonobject logindetailsjson = new jsonobject(); logindetailsjson.put("id", jsonobject.getstring("id")); logindetailsjson.put("name", jsonobject.getstring("name")); logindetailsjson.put("first_name", jsonobject.getstring("first_name")); logindetailsjson.put("last_name", jsonobject.getstring("last_name")); logindetailsjson.put("link", jsonobject.getstring("link")); logindetailsjson.put("gender", jsonobject.getstring("gender")); logindetailsjson.put("locale", jsonobject.getstring("locale")); logindetailsjson.put("timezone", jsonobject.getstring("timezone")); logindetailsjson.put("email", jsonobject.getstring("email")); logindetailsjson.put("verified", jsonobject.getstring("verified")); logindetailsjson.put("updated_time", jsonobject.getstring("updated_time")); logindetailsjson.put("age_range", ""); logindetailsjson.put("connector", "fb"); jsonobjectrequest req = new jsonobjectrequest(request.method.post, connetionstrings.loginurl, logindetailsjson.tostring(), new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { try { volleylog.v("response:%n %s", response.tostring(4)); log.d("response: ", response.tostring(4)); } catch (jsonexception e) { e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.e("error: ", error.getmessage()); toast toast = toast.maketext(getapplicationcontext(), "please try again", toast.length_long); toast.show(); } }); mrequestqueue.add(req); intent done = new intent(getbasecontext(), mainactivity.class); startactivity(done); } catch (jsonexception e) { e.printstacktrace(); } } } }).executeasync(); } @override public void oncancel() { log.d("tag_cancel", "on cancel"); } @override public void onerror(facebookexception error) { log.d("tag_error", error.tostring()); } }); }
look @ https://developers.facebook.com/docs/facebook-login/android/v2.3#get_current , check, if implemented (what i'm missing in code onactivityresult callback). don't put initation of callback onfblogin method - put directly in oncreate. don't have add listener loginbutton. works after inflation. , visibility of ui elements can change in callback methods of facebookcallback listener (make activity implementation of it).
Comments
Post a Comment