How to get email id From Android Facebook SDK 4.6.0? -


here code getting user information after facebook login. trying emailid user getting name , id , not getting emailid .i have tried login button , login manager class both giving same results . how email id response :

loginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() {                 @override                 public void onsuccess(final loginresult loginresult) {                     new graphrequest(accesstoken.getcurrentaccesstoken(),                             "/me", null , httpmethod.get,                             new graphrequest.callback() {                                 public void oncompleted(                                         graphresponse response) {                                          handle result                                       if (response !=null  )                                     {                                         //get user information                                         toast.maketext(getapplicationcontext(),"hello in json",toast.length_long).show();                                         jsonobject json = response.getjsonobject();                                         //jsonarray jsona = response.getjsonarray();                                         log.i(tag,"" +json);                                        // log.i(tag,"" +json);                                         string email = json.optstring("email");                                        // string email = json.optstring("email");                                         //log.i("email", "" + email);                                         log.i(tag,"" +email);                                         string fullname = json.optstring("name");                                         string location = json.optstring("location");                                         string accesstoken = loginresult.getaccesstoken().gettoken();                                         string user_id = json.optstring("id");                                         log.i(tag,"" +json);                                         toast.maketext(getapplicationcontext(),fullname,toast.length_long).show();                                         toast.maketext(getapplicationcontext(),email,toast.length_long).show();                                         toast.maketext(getapplicationcontext(),user_id,toast.length_long).show();                                         //int type = 1;                                        // string lastupdate = json.getstring("updated_time");                                        //  log.i("email", "" + email);                                       //  log.i("message", "hello");                                         log.i("name", "" + fullname);                                         log.i("id", "" + user_id);                                       }                                 }                              }).executeasync(); 

thanks..!!

loginmanager.getinstance().loginwithreadpermissions(welcomeactivity1.this, (arrays.aslist("public_profile", "user_friends","user_birthday","user_about_me","email")));  string email;   loginmanager.getinstance().registercallback(callbackmanager,new facebookcallback<loginresult>() {  @override   public void onsuccess(loginresult loginresult) {   log.d("tag","ff fb onsuccess");   graphrequest request = graphrequest.newmerequest(loginresult.getaccesstoken(),new graphrequest.graphjsonobjectcallback() {     @override     public void oncompleted(jsonobject object,graphresponse response) {      try {            string[] splited ;            jsonobject obj =  object.getjsonobject("picture").getjsonobject("data");                                if (object.has("email"))                               {                                  email =  object.getstring("email");                               }                               else                               {                                   email = "";                               }                                } catch (jsonexception e) {                                 // todo auto-generated catch block                                 e.printstacktrace();                             }                               }                         });                 bundle parameters = new bundle();                 parameters.putstring("fields", "id,name,link,birthday,picture,email,gender");                 request.setparameters(parameters);                 request.executeasync();               }              @override             public void oncancel() {                 log.d("tag","fb oncancel");                  // app code             }    @override             public void onerror(facebookexception exception) {                 log.d("tag","fb onerror");                  // app code                } }); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -