I am using Facebook SDK 4 ,I had Do this before sdk 2... but for me some syntax has changed so I had faced some problem... I'm not able to fetch username,email
This is my XML File
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.login.widget.LoginButton
android:id="@+id/LoginFbButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Login With Facebook" />
</LinearLayout>
This Is My Code For Login with Facebook
private void loginToFacebook() {
Session.openActiveSession(this, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Log.i(TAG, "Access Token" + session.getAccessToken());
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
try {
firstName=user.getFirstName();
lastName=user.getLastName();
Log.d("Facebook User", "details:" + firstName+""+lastName);
}catch(Exception e){
See My Logcat
com.facebook.katana.platform.PlatformService has leaked ServiceConnection com.facebook.fbservice.ops.DefaultBlueServiceOperationFactory$DefaultOperation$BlueServiceConnection@4307e1d8 that was originally bound here E/ActivityThread(28413): android.app.ServiceConnectionLeaked: Service com.facebook.katana.platform.PlatformService has leaked ServiceConnection com.facebook.fbservice.ops.DefaultBlueServiceOperationFactory$DefaultOperation$BlueServiceConnection@4307e1d8 that was originally bound here