Facebook Android SDK 4.0 not returning emailID -


i trying implement facebook login using latest facebook sdk 4.0.it returning user-id , user-name. below code have implemented using graph apis.

@override     public void onviewcreated(view view, bundle savedinstancestate) {         super.onviewcreated(view, savedinstancestate);         loginbutton loginbutton = (loginbutton) view.findviewbyid(r.id.login_button);         textview = (textview) view.findviewbyid(r.id.textview);          list<string> permissions = new arraylist<>();         //permissions.add("user_friends");         permissions.add("email");         //permissions.add("user_birthday");         loginbutton.setreadpermissions(permissions);         loginbutton.setfragment(this);         loginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() {             @override             public void onsuccess(loginresult loginresult) {                 graphrequest.newmerequest(                         loginresult.getaccesstoken(),new graphrequest.graphjsonobjectcallback() {                              @override                             public void oncompleted(jsonobject jsonobject, graphresponse graphresponse) {                                 if (graphresponse.geterror() != null) {                                     // handle error                                 } else {                                     string email = jsonobject.optstring("email");                                     string id = jsonobject.optstring("id");                                     new graphrequest(                                             accesstoken.getcurrentaccesstoken(),                                             "/" + id,                                             null,                                             httpmethod.get,                                             new graphrequest.callback() {                                                 @override                                                 public void oncompleted( graphresponse graphresponse) {                                                         log.d("facebook login","graph response" +graphresponse.tostring());                                                 }                                             }                                     ).executeasync();                                     log.d("facebook login ","email id , user_id of looged in user = ::" + email+" ::"+id+"" +                                             "jsonobject facebook getting :" +jsonobject.tostring());                                     // send email , id web server                                 }                              }                          }).executeasync();             }              @override             public void oncancel() {              }              @override             public void onerror(facebookexception e) {              }         });      } 

also tried using graph api explorer, showing me email address birthday , gender too. below snapshot of

snapshot of graphapi explorer

try .

    string username,email ;      loginbutton.registercallback(callbackmanager,                 new facebookcallback<loginresult>() {                     @override                     public void onsuccess(loginresult loginresult) {                         new fblogin().execute(loginresult.getaccesstoken());                      }                      @override                     public void oncancel() {                      }                      @override                     public void onerror(facebookexception e) {                      }                 });     class fblogin extends asynctask<accesstoken, string, string> {          @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(login.this);             pdialog.setmessage("loading data..");             pdialog.setindeterminate(false);             pdialog.setcancelable(false);             pdialog.show();         }          protected string doinbackground(accesstoken... params) {             graphrequest request = graphrequest.newmerequest(params[0],                     new graphrequest.graphjsonobjectcallback() {                         @override                         public void oncompleted(jsonobject object,                                 graphresponse response) {                              try {                                  username = object.getstring("first_name");                                  emailid = object.getstring("email");                               } catch (jsonexception e) {                                 // todo auto-generated catch                                 // block                                 e.printstacktrace();                             }                         }                     });             bundle parameters = new bundle();             parameters.putstring("fields",                     "id,first_name,email,gender,birthday");             request.setparameters(parameters);             request.executeandwait();              return null;         }          protected void onpostexecute(string file_url) {              pdialog.dismiss();          }      } 

its done.!!


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -