Android: Parse + Facebook integration -
i working on parse , facebook integration reference tutorial https://github.com/parseplatform/integratingfacebooktutorial/tree/master/integratingfacebooktutorial-android, , come across headache problems can offer advice.
loginactivity.java
oncreate .... // check if there logged in user , it's linked facebook account. parseuser currentuser = parseuser.getcurrentuser(); if ((currentuser != null) && parsefacebookutils.islinked(currentuser)) { // go user info activity showuserdetailsactivity(); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); parsefacebookutils.onactivityresult(requestcode, resultcode, data); } public void onloginclick(view v) { progressdialog = progressdialog.show(loginactivity.this, "", "logging in...", true); list<string> permissions = arrays.aslist( "public_profile", "user_friends", "email", "user_birthday" ); parsefacebookutils.loginwithreadpermissionsinbackground(this, permissions, new logincallback() { @override public void done(parseuser user, parseexception err) { progressdialog.dismiss(); if (user == null) { log.d(msg, "uh oh. user cancelled facebook login."); utilities.custom_toast(loginactivity.this, "uh oh. user cancelled facebook login.", "gone!", "short"); } else if (user.isnew()) { log.d(msg, "user signed , logged in through facebook!"); utilities.custom_toast(loginactivity.this, "user signed , logged in through facebook!", "gone!", "short"); showuserdetailsactivity(); } else { log.d(msg, "user logged in through facebook!"); utilities.custom_toast(loginactivity.this, "user logged in through facebook!", "gone!", "short"); showuserdetailsactivity(); } } }); } private void showuserdetailsactivity() { intent intent = new intent(this, userdetails.class); startactivity(intent); }
userdetails.java
@override protected void onresume() { super.onresume(); parseuser currentuser = parseuser.getcurrentuser(); if (currentuser != null) { // check if user logged , show cached content updateviewswithprofileinfo(); } else { // if user not logged in, go activity showing login view. startloginactivity(); } } private void makemerequest() { graphrequest request = graphrequest.newmerequest(accesstoken.getcurrentaccesstoken(), new graphrequest.graphjsonobjectcallback() { @override public void oncompleted(jsonobject jsonobject, graphresponse graphresponse) { if (jsonobject != null) { jsonobject userprofile = new jsonobject(); try { userprofile.put("facebookid", jsonobject.getlong("id")); userprofile.put("name", jsonobject.getstring("name")); if (jsonobject.getstring("gender") != null) userprofile.put("gender", jsonobject.getstring("gender")); if (jsonobject.getstring("email") != null) userprofile.put("email", jsonobject.getstring("email")); // save user profile info in user property parseuser currentuser = parseuser.getcurrentuser(); currentuser.put("user", userprofile); currentuser.saveinbackground(); // show user info updateviewswithprofileinfo(); } catch (jsonexception e) { log.d(tag,"error parsing returned user data. " + e); } } else if (graphresponse.geterror() != null) { switch (graphresponse.geterror().getcategory()) { case login_recoverable: utilities.custom_toast(userdetails.this, "authentication error: " + graphresponse.geterror(), "gone!", "short"); break; case transient: utilities.custom_toast(userdetails.this, "transient error. try again" + graphresponse.geterror(), "gone!", "short"); log.d(tag,"transient error. try again. " + graphresponse.geterror()); break; case other: utilities.custom_toast(userdetails.this, "some other error: " + graphresponse.geterror(), "gone!", "short"); log.d(tag,"some other error: " + graphresponse.geterror()); break; } } } }); request.executeasync(); } private void updateviewswithprofileinfo() { parseuser currentuser = parseuser.getcurrentuser(); if (currentuser.has("profile")) { jsonobject userprofile = currentuser.getjsonobject("profile"); try { if (userprofile.has("name")) { usernameview.settext(userprofile.getstring("name")); } else { usernameview.settext("no name"); } if (userprofile.has("gender")) { usergenderview.settext(userprofile.getstring("gender")); } else { usergenderview.settext("no gender"); } if (userprofile.has("email")) { useremailview.settext(userprofile.getstring("email")); } else { useremailview.settext("no email"); } } catch (jsonexception e) { log.d(tag, "error parsing saved user data."); } } else { utilities.custom_toast(userdetails.this, "no profile!", "gone!", "short"); } } public void onlogoutclick(view v) { logout(); } private void logout() { parseuser.logout(); // log user out startloginactivity(); // go login view } private void startloginactivity() { intent intent = new intent(this, loginactivity.class); intent.addflags(intent.flag_activity_clear_top); intent.addflags(intent.flag_activity_new_task); startactivity(intent); }
question:
i have tried run app new user: 1. when press login button, process , pop "user signed , logged in through facebook!" however, after logged in, turns userdetails
page, reports via toast "no profile!" , ie currentuser has no info inside. going wrong here?
- why there no permission page popup when login despite got "email" permission?
thanks lot!
Comments
Post a Comment