How to fetch user details on simple button on click not facebook button in android? -


i integrating facebook login in android app in want when simple button click want fetch user details.i not want place facebook login button. how can

here code:-

private button loginbutton; private callbackmanager callbackmanager;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     facebooksdk.sdkinitialize(getapplicationcontext());     callbackmanager = callbackmanager.factory.create();     setcontentview(r.layout.activity_main);      loginbutton = (button) findviewbyid(r.id.login_button);     loginbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             loginmanager.getinstance().loginwithreadpermissions(mainactivity.this, arrays.aslist("public_profile, email, user_birthday, user_friends"));         }     });     loginmanager.getinstance().registercallback(callbackmanager,             new facebookcallback<loginresult>() {                 @override                 public void onsuccess(final loginresult loginresult) {                     log.d("success", "login");                     graphrequest request = graphrequest.newmerequest(                             loginresult.getaccesstoken(),                             new graphrequest.graphjsonobjectcallback() {                                 @override                                 public void oncompleted(jsonobject object, graphresponse response) {                                     log.e("json:", object.tostring());                                     string user_id = null;                                     try {                                         user_id = object.getstring("id");                                     } catch (jsonexception e) {                                         e.printstacktrace();                                     }                                     cfacbookstorage facebookstorage = new cfacbookstorage();                                     facebookstorage.setm_userid(user_id);                                     intent = new intent(mainactivity.this, cfacebookdeatails.class);                                     i.putextra("user_data", facebookstorage);                                     startactivity(i);                                 }                             });                     bundle parameters = new bundle();                     parameters.putstring("fields", "id,name,email,gender, birthday");                     request.setparameters(parameters);                     request.executeasync();                  }                  @override                 public void oncancel() {                     // toast.maketext(login.this, "login cancel", toast.length_long).show();                 }                  @override                 public void onerror(facebookexception exception) {                     toast.maketext(mainactivity.this, exception.getmessage(), toast.length_long).show();                 }             });     accesstoken token;     token = accesstoken.getcurrentaccesstoken();       if (token == null) {         //means user not logged in     } else {         log.d("tag", "init: facebooklogin   " + accesstoken.user_id_key + "   " + accesstoken.access_token_key + "  ");     }     loginbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             loginmanager.getinstance().loginwithreadpermissions(mainactivity.this, arrays.aslist("public_profile, email, user_birthday, user_friends"));          }     }); }   @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     callbackmanager.onactivityresult(requestcode, resultcode, data); } 

}

cfacbookstorage class code:-

    public static cfacbookstorage cfacbookstorage;  public string getm_userid() {     return m_userid; }  public void setm_userid(string m_userid) {     this.m_userid = m_userid; }  public string m_userid;  public static cfacbookstorage getinstance(){     if (cfacbookstorage==null){         cfacbookstorage = new cfacbookstorage();     }     return cfacbookstorage; } 

}

cfacebookdetail

private textview info; @override protected void oncreate(@nullable bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.dialog_details);     info = (textview)findviewbyid(r.id.info);  } 

in code getting error in loginbutton.registercallback(){}

used button in xml file after in oncreate of activity use below code:

private callbackmanager callbackmanager;  callbackmanager = callbackmanager.factory.create();          loginmanager.getinstance().registercallback(callbackmanager,                 new facebookcallback<loginresult>() {                     @override                     public void onsuccess(final loginresult loginresult) {                         log.d("success", "login");                         graphrequest request = graphrequest.newmerequest(                                 loginresult.getaccesstoken(),                                 new graphrequest.graphjsonobjectcallback() {                                     @override                                     public void oncompleted(                                             jsonobject object,                                             graphresponse response) {                                         // application code                                         response.geterror();                                         log.e("json:", object.tostring());                                     }                                 });                         bundle parameters = new bundle();                         parameters.putstring("fields", "id,name,email,gender, birthday");                         request.setparameters(parameters);                         request.executeasync();                      }                      @override                     public void oncancel() {                         // toast.maketext(login.this, "login cancel", toast.length_long).show();                     }                      @override                     public void onerror(facebookexception exception) {                         toast.maketext(signinactivity.this, exception.getmessage(), toast.length_long).show();                     }                 });         accesstoken token;         token = accesstoken.getcurrentaccesstoken();           if (token == null) {             //means user not logged in         } else {             log.d("tag", "init: facebooklogin   " + accesstoken.user_id_key + "   " + accesstoken.access_token_key + "  ");         } 

after add below code on button click event:

button.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                     loginmanager.getinstance().loginwithreadpermissions(signinactivity.this, arrays.aslist("public_profile, email, user_birthday, user_friends"));              }         }); 

the put in activity

 @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         callbackmanager.onactivityresult(requestcode, resultcode, data);     } 

Comments