I need user's email address after successful facebook login in android using SDK 4.0 -


i have integrated latest facebook android sdk 4.0. in sdk 3.0+ user's email address retreived using user.getproperty("email") after successful login. looking corresponding command in facebook android sdk 4.0 reference links:

https://developers.facebook.com/docs/facebook-login/android/v2.3#overview https://developers.facebook.com/docs/android/upgrading-4.x

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     facebooksdk.sdkinitialize(getactivity().getapplicationcontext());     callbackmanager = callbackmanager.factory.create(); }  @override public void onviewcreated(view view, @nullable bundle savedinstancestate) {     super.onviewcreated(view, savedinstancestate);     loginbutton = (loginbutton) view.findviewbyid(r.id.login_button);     loginbutton.setreadpermissions("email", "user_likes", "user_friends");     loginbutton.setfragment(this);     setfacebooklogintext(loginbutton);     // other app specific specialization      // callback registration     loginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() {         @override         public void onsuccess(loginresult loginresult) {             accesstoken accesstoken = loginresult.getaccesstoken();             graphrequest request = graphrequest.newmerequest(accesstoken, new graphrequest.graphjsonobjectcallback() {                 @override                 public void oncompleted(jsonobject user, graphresponse graphresponse) {                    //need user email address after login success.                  }             }).executeasync();         }          @override         public void oncancel() {             toast.maketext(getactivity(), "fail", toast.length_short).show();         }          @override         public void onerror(facebookexception exception) {             toast.maketext(getactivity(), "error", toast.length_short).show();         }     });  }  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view view = inflater.inflate(r.layout.fragment_facebook_login, container, false);     return view; }   @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     callbackmanager.onactivityresult(requestcode, resultcode, data); } 

yeah worked. thing required change graphrequest graphrequestasynctask in onsuccess method of facebookcallback, , user details fetched jsonobject.

        @override         public void onsuccess(loginresult loginresult) {             final accesstoken accesstoken = loginresult.getaccesstoken();             final fbuser fbuser = new fbuser();             graphrequestasynctask request = graphrequest.newmerequest(accesstoken, new graphrequest.graphjsonobjectcallback() {                 @override                 public void oncompleted(jsonobject user, graphresponse graphresponse) {                     fbuser.setemail(user.optstring("email"));                     fbuser.setname(user.optstring("name"));                     fbuser.setid(user.optstring("id"));                 }             }).executeasync();         } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -