mysql - Sending Facebook user data to server fails - Android -


i have app facebook login (4.2), when user logs in, pass data (name, birthday, etc) mysql online database. problem on devices empty strings, , can't figure out why?

the user data sent server in oncompleted() method, inside onsucces() after saved preferences:

public class splashactivity extends activity {      private loginbutton loginbutton;     callbackmanager callbackmanager;     private editor editor;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         getwindow().requestfeature(window.feature_action_bar);         getactionbar().hide();         setcontentview(r.layout.splash);          facebooksdk.sdkinitialize(getapplicationcontext());         callbackmanager = callbackmanager.factory.create();          loginbutton = (loginbutton) findviewbyid(r.id.login_button);         loginbutton.setreadpermissions(arrays.aslist("public_profile, email, user_birthday, user_friends"));          editor = this.getsharedpreferences("userinfo", context.mode_private).edit();          isloggedin();           if (isloggedin()) {             loginbutton.setvisibility(view.gone);             new countdowntimer(3000, 5000) {                 public void ontick(long millisuntilfinished) {                 }                  public void onfinish() {                     finish();                 }              }.start();         } else {          }           // callback registration         loginbutton.registercallback(callbackmanager,                 new facebookcallback<loginresult>() {                     @override                     public void onsuccess(loginresult loginresult) {                         // app code                         graphrequest request = graphrequest.newmerequest(                                 loginresult.getaccesstoken(),                                 new graphrequest.graphjsonobjectcallback() {                                                                     @override                                     public void oncompleted(jsonobject object, graphresponse response) {                                                                                 try {                                              string id = (string) object.get("id");                                             string name = (string) object.get("name");                                             string email = (string) object.get("email");                                             string birthday = (string) object.get("birthday");                                              editor.putstring("id", id);                                             editor.putstring("name", name);                                             editor.putstring("email", email);                                             editor.putstring("birthday", birthday);                                              editor.commit();                                              senduserinfo sender = new senduserinfo(getapplication());                                             sender.senduserinfo();                                          } catch (jsonexception e) {                                                                                      e.printstacktrace();                                         }                                      }                                 });                         bundle parameters = new bundle();                         parameters.putstring("fields", "id,name, email, gender, birthday");                         request.setparameters(parameters);                         request.executeasync();                          finish();                     }                      @override                     public void oncancel() {                         // app code                     }                      @override                     public void onerror(facebookexception exception) {                         toast.maketext(getapplication(),                                 "va rugam sa incercati mai tarziu.",                                 toast.length_long).show();                     }                 });      }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         callbackmanager.onactivityresult(requestcode, resultcode, data);     }      public boolean isloggedin() {         accesstoken accesstoken = accesstoken.getcurrentaccesstoken();         return accesstoken != null;     }  } 

class upload data:

public class senduserinfo {      context context;     private int refcode;       public senduserinfo(context context) {         this.context = context;     }  public void senduserinfo () {          sharedpreferences preferences = context.getsharedpreferences("userinfo",                 context.mode_private);         string regid = preferences.getstring("userregid", null);         string id = preferences.getstring("id", "null");         string name = preferences.getstring("name", null);         string email = preferences.getstring("email", null);         string birthday = preferences.getstring("birthday", null);           random r = new random();         refcode = r.nextint(9000 - 6000) + 456;                final int default_timeout = 10000;         asynchttpclient client = new asynchttpclient();         client.settimeout(default_timeout);          requestparams params = new requestparams();               params.put("regid", regid);          params.put("fbid", id);         params.put("name", name);          params.put("email", email);          params.put("birthday", birthday);          params.put("refcode", string.valueof(refcode));             client.post("http://www.edmondvarga.com/laborator/save-user-info.php",                 params, new asynchttpresponsehandler() {                      @override                     public void onfailure(int arg0, header[] arg1, byte[] arg2,                             throwable arg3) {                         senduserinfo();                      }                      @override                     public void onsuccess(int arg0, header[] arg1, byte[] arg2) {                      }                 });      }   } 

some users may not have valid emails or birthdays (even if give permission), need handle empty fields. guarantee you'll unique id per user.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -