Facebook Android SDK 4.5.0 get email address -


i'm creating test application test using latest facebook sdk update our existing application problem need email address know depends if user has provided 1 on account. account i'm using test provides 1 sure unknown reason facebook sdk provides user_id , fullname of account , nothing else. i'm confused on since the sdk3 , above provides more information updated sdk4 , i'm lost on how email answers i've seen far doesn't provide email on end. here's code far:

login button

@onclick(r.id.btn_login)     public void loginfacebook(){         loginmanager.getinstance().loginwithreadpermissions(this, arrays.aslist("public_profile", "email"));     } 

loginmanager callback:

loginmanager.getinstance().registercallback(callbackmanager, new facebookcallback<loginresult>() {             @override             public void onsuccess(loginresult loginresult) {                 requestuserprofile(loginresult);             }              @override             public void oncancel() {                 toast.maketext(getbasecontext(),"login cancelled", toast.length_short).show();             }              @override             public void onerror(facebookexception e) {                 toast.maketext(getbasecontext(),"problem connecting facebook", toast.length_short).show();             }         }); 

and request user profile:

public void requestuserprofile(loginresult loginresult){         graphrequest.newmerequest(                 loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() {                     @override                     public void oncompleted(jsonobject me, graphresponse response) {                         if (response.geterror() != null) {                             // handle error                         } else {                             try {                                 string email = response.getjsonobject().get("email").tostring();                                 log.e("result", email);                             } catch (jsonexception e) {                                 e.printstacktrace();                             }                             string id = me.optstring("id");                             // send email , id web server                             log.e("result1", response.getrawresponse());                             log.e("result", me.tostring());                         }                     }                 }).executeasync();     } 

the json response returns id , full name of account doesn't include email. did missed out something?

you need ask parameters facebook in order data. here post function facebook data. key in line:

parameters.putstring("fields", "id, first_name, last_name, email,gender, birthday, location"); // parĂ¡metros que pedimos facebook 

hope helps you.

btnloginfb.registercallback(callbackmanager, new facebookcallback<loginresult>() {          @override         public void onsuccess(loginresult loginresult) {              system.out.println("onsuccess");             progressdialog = new progressdialog(loginactivity.this);             progressdialog.setmessage("procesando datos...");             progressdialog.show();             string accesstoken = loginresult.getaccesstoken().gettoken();             log.i("accesstoken", accesstoken);              graphrequest request = graphrequest.newmerequest(loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() {                  @override                 public void oncompleted(jsonobject object, graphresponse response) {                     log.i("loginactivity", response.tostring());                     // facebook data login                     bundle bfacebookdata = getfacebookdata(object);                  }             });             bundle parameters = new bundle();             parameters.putstring("fields", "id, first_name, last_name, email,gender, birthday, location"); // parĂ¡metros que pedimos facebook             request.setparameters(parameters);             request.executeasync();         }          @override         public void oncancel() {             system.out.println("oncancel");         }          @override         public void onerror(facebookexception exception) {             system.out.println("onerror");             log.v("loginactivity", exception.getcause().tostring());         }     });    private bundle getfacebookdata(jsonobject object) {          try {             bundle bundle = new bundle();             string id = object.getstring("id");              try {                 url profile_pic = new url("https://graph.facebook.com/" + id + "/picture?width=200&height=150");                 log.i("profile_pic", profile_pic + "");                 bundle.putstring("profile_pic", profile_pic.tostring());              } catch (malformedurlexception e) {                 e.printstacktrace();                 return null;             }              bundle.putstring("idfacebook", id);             if (object.has("first_name"))                 bundle.putstring("first_name", object.getstring("first_name"));             if (object.has("last_name"))                 bundle.putstring("last_name", object.getstring("last_name"));             if (object.has("email"))                 bundle.putstring("email", object.getstring("email"));             if (object.has("gender"))                 bundle.putstring("gender", object.getstring("gender"));             if (object.has("birthday"))                 bundle.putstring("birthday", object.getstring("birthday"));             if (object.has("location"))                 bundle.putstring("location", object.getjsonobject("location").getstring("name"));              return bundle;         }       catch(jsonexception e) {         log.d(tag,"error parsing json");       }     return null; } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -