111 thoughts on “Login With Facebook Android Studio using Facebook SDK 4”

  1. When i create a Blank Activity with Fragment it creates me an activity that extends from ActionBarActivity and then creates a class that extends from Fragment, how can i execute my MainFragment from an class that extends form ActionBarActivity.

    Reply
  2. Your tutorial is great and helped me a lot but I want to create the login button on a popup window, how should I do that? and how can I hide the login button when the user has already loged in? and will you do some tutorials on facebook sharing and like button too?

    Reply
  3. Is there a way to use the FB SDK log in button without using a fragment? Can I just put it straight on the MainActivity? If so, how do I do this?

    Reply
  4. Thanks man! I got your site after one week and you wont believe even after trying millions of options it dint work. Amazing work 😀

    Reply
  5. I try this code butt my application not open just an error message shown “Your application is forcefully stoped”

    Reply
  6. I need to get the email id, phone number , password of the after login. please suggest how to get that. Thanks i advance.

    Reply
  7. Thanks a lot! work 100%.. How I can start another activity after login ? And how can I pass the parameters of facebook to the new activity?

    Reply
  8. Hi, great tutorial but i seem to have an error through your code. when i run inspect code in android studio it comes up with an error such as…

    Location     
     class anonymous in FacebookCallback callback (mobliedevelopment.terrelsimeongordon.hwl_fb.MainFragment)  

     Problem synopsis     
     Variable ‘accessToken’ at line 38 is never used

    i downloaded the source code yet the same error comes up

    this is the code that android is complaining about?

    private FacebookCallback callback = new FacebookCallback() {
    @Override
    public void onSuccess(LoginResult loginResult) {
    AccessToken accessToken = loginResult.getAccessToken();
    Profile profile = Profile.getCurrentProfile();
    displayMessage(profile);
    }

    do you have any clue why it is not working and why it can not find accessToken? grateful if you could help answer this 1 million dollar question 🙂

    Reply
    • Hi sorry about that i just found the issue 🙂
      just wondering if its possible to extend just an activity instead of an ActionBarActivity for the MainActivity? if so how would you i go about altering this code to that requirement?

      Reply
  9. How do i change the height and width of the Login button ( com.facebook.login.widget.LoginButton ) i m using the 4.1 sdk for facebook

    Reply
  10. I need to get email Id of the user, added the permission of it too but How do i print that in the TextView. Profile.getEmailID(); doesn’t work. Please help

    Reply
  11. i need the friend list of my friends but i m not.
    plz tell me the permissions to write for it how can we aceess all that ..
    i am new in android

    Reply
  12. The problem is how to call another activity right after authorization succeed and remove logout button.

    thanks in advance……

    Reply
    • Session and graph is not working in this sdk version. so please give the code to get the complete profile information.

      your tutorial heiped me to get the username from profile using profile.getName();

      similarly i need to get the all profile information. please give the code.

      Thanks in advance

      Reply
  13. login page of facebook appeared only once during the first run. Subsequent running doesnt show it.Please help me.
    also during debugging, variable profile gets null value. iam a beginner to android. please help

    Thanks

    Reply
  14. getting error in logcat please sir help me

    Error:A problem occurred configuring project ‘:app’.
    > Could not download facebook-android-sdk.aar (com.facebook.android:facebook-android-sdk:4.0.0)
    > Could not get resource ‘https://jcenter.bintray.com/com/facebook/android/facebook-android-sdk/4.0.0/facebook-android-sdk-4.0.0.aar’.
    > Could not GET ‘https://jcenter.bintray.com/com/facebook/android/facebook-android-sdk/4.0.0/facebook-android-sdk-4.0.0.aar’.
    > d29vzk4ow07wi7.cloudfront.net

    Reply
  15. Hi,

    I am able to integrate facebook login into my app successfully by follwing your post. The actual req of my app is to trigger facebook status at the end of every month. When i try to login after two months login dialog does not open up. It throws a FacebookAuthorizationException. Can you please help me in figuring it out.

    Note: I believe due to access token expiry facebook login dialog does not open. You can check it

    Thanks.

    Reply
  16. 10-16 15:59:05.620 1304-1335/? E/InputDispatcher﹕ channel ‘c10b4fa com.example.dipali.androidlogin/com.example.dipali.androidlogin.MainActivity (server)’ ~ Channel is unrecoverably broken and will be disposed!

    I have this error.How can i solve this error?

    Reply
  17. Couldn’t load memtrack module (No such file or directory)
    10-17 11:11:42.089 2347-2347/? E/android.os.Debug﹕ failed to load memtrack module: -2
    10-17 11:11:49.677 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
    10-17 11:11:49.677 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn’t include a PendingIntent in the extras?
    10-17 11:11:50.245 2384-2384/? E/memtrack﹕ Couldn’t load memtrack module (No such file or directory)
    10-17 11:11:50.246 2384-2384/? E/android.os.Debug﹕ failed to load memtrack module: -2
    10-17 11:11:50.345 2384-2392/? E/art﹕ Thread attaching while runtime is shutting down: Binder_1
    10-17 11:11:53.054 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
    10-17 11:11:53.055 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn’t include a PendingIntent in the extras?
    10-17 11:11:59.472 2393-2393/? E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
    10-17 11:11:59.956 2393-2393/? E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
    10-17 11:11:59.956 2393-2393/? E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
    10-17 11:11:59.956 2393-2393/? E/chromium﹕ [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
    10-17 11:11:59.956 2393-2393/? E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
    10-17 11:11:59.956 2393-2393/? E/chromium﹕ [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
    10-17 11:12:00.266 2393-2393/? E/DataReductionProxySettingListener﹕ No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
    10-17 11:12:00.913 953-953/? E/SELinux﹕ avc: denied { find } for service=batteryproperties scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:healthd_service:s0 tclass=service_manager
    10-17 11:12:04.515 2393-2474/? A/chromium﹕ [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
    ——— beginning of crash
    10-17 11:12:04.515 2393-2474/? A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 2474 (GpuThread)
    10-17 11:12:04.634 962-962/? A/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    10-17 11:12:04.634 962-962/? A/DEBUG﹕ Build fingerprint: ‘generic_x86/sdk_google_phone_x86/generic_x86:6.0/MRA44C/2166767:eng/test-keys’
    10-17 11:12:04.634 962-962/? A/DEBUG﹕ Revision: ‘0’
    10-17 11:12:04.634 962-962/? A/DEBUG﹕ ABI: ‘x86’
    10-17 11:12:04.634 962-962/? A/DEBUG﹕ pid: 2393, tid: 2474, name: GpuThread >>> com.example.dipali.androidlogin <<>> com.example.dipali.androidlogin <<<
    10-17 11:15:52.846 962-962/? A/DEBUG﹕ signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr ——–
    10-17 11:15:52.851 962-962/? A/DEBUG﹕ Abort message: '[FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
    '
    10-17 11:15:52.851 962-962/? A/DEBUG﹕ eax 00000000 ebx 000009b2 ecx 00000a05 edx 00000006
    10-17 11:15:52.851 962-962/? A/DEBUG﹕ esi a04bf980 edi 00000000
    10-17 11:15:52.851 962-962/? A/DEBUG﹕ xcs 00000073 xds 0000007b xes 0000007b xfs 000000c7 xss 0000007b
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ eip b73b55d6 ebp 00000a05 esp a04bec40 flags 00200206
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ backtrace:
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ #00 pc 000845d6 /system/lib/libc.so (tgkill+22)
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ #01 pc 00081618 /system/lib/libc.so (pthread_kill+70)
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ #02 pc 00027205 /system/lib/libc.so (raise+36)
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ #03 pc 000209e4 /system/lib/libc.so (abort+80)
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ #04 pc 0037328a /system/app/webview/webview.apk
    10-17 11:15:52.852 962-962/? A/DEBUG﹕ #05 pc 000009a3 /data/misc/shared_relro/libwebviewchromium32.relro
    10-17 11:15:53.423 962-962/? A/DEBUG﹕ Tombstone written to: /data/tombstones/tombstone_03
    10-17 11:15:53.423 962-962/? E/DEBUG﹕ AM write failed: Broken pipe
    10-17 11:15:56.910 954-954/? E/libEGL﹕ called unimplemented OpenGL ES API
    10-17 11:15:56.911 954-954/? E/SurfaceFlinger﹕ glCheckFramebufferStatusOES error -2129925904
    10-17 11:15:56.911 954-954/? E/SurfaceFlinger﹕ got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot

    Reply
  18. Hi, that was an really awesome tutorial, I run the app, go the output. But I tried to reopen means its shows the HashKey error. Please guide me

    Reply
  19. Hi Belal u have done a good job. I tried many totorials but got disappointed. i used your tutorial in my case it is working, but if i try to login second time it shows the message “This app has no Android key hashes configured. pls configure hash key. but i configured key hash succesfully still get error msg from second time login.. pls help me..

    Reply
  20. I am making one movie review app, and I tried to create a login with facebook button at my login page.
    When I start my app for 1st time, then it works fine, get logged in from Facebook, and also able to display name.
    But after the 1st time when I log out from it, and try to log in again, then it always shows ” The app has no Android key hashes configured. Configure your app key hashes at …………”
    Please guide me and help me with solution to it. Please as I have to submit it as a project day after tomorrow. please

    Reply
  21. i have issue when i created facebook app id then :

    There was a problem verifying the package name com.example.vicky.facelogin on Google Play. Please check the package name and try again.
    If your app isn’t listed publicly on Google Play yet you can ignore this message

    please help me

    Reply
  22. Hi belal, awesome tut! 🙂
    i am not getting my KEY HASH on log cat 🙁 and tried it by using openSsl also bt it is also not working.. can you please help me.. 🙁

    Reply
    • Hi Belal,
      I have tried your code and it’s working as i want but i have one question that now i want to save user data who login with facebook at mysql database. I have POST Json API but not getting anything after spending hours on google. Can anyone help me ?

      Reply
  23. Hi Bilal,
    Thank you for this great tutorial. I just want to share one solution for those who’s getting error of hash key. When you run your programme at first time it’s successfully login but second time it give error of hash key. The solution is the key which is shown in device as a error is your correct hash key so save this key on facebook app setting and the error is gone. thanks

    Reply
  24. Hi thanks for this tutorial. I successfully created and executed the app.
    But i want to get facebook friends list. I saw the documentation and it was little bit confusing. How to proceed , please help. Thanks in advance.

    Reply
  25. Hello there, i have seen this tutorial and it is very useful to me, but i have one question. How can i create a login activity with facebook in it? Means that there is simple login button and i don’t want to use fragment for it. So how to do this, can you explain or give me some idea to do it. Thanks for help!!!

    Reply
  26. I got a FacebookException i.e. couldn’t connect to the server, after click on login button and comes progress bar.
    please reply, thanks in advance.

    Reply
  27. Log in attempt failed: LoginActivity could not be started
    at com.facebook.login.LoginManager.startLogin(LoginManager.java:382)

    i have run app then above error show

    if (!started) {
    FacebookException exception = new FacebookException(
    “Log in attempt failed: LoginActivity could not be started”);
    logCompleteLogin(LoginClient.Result.Code.ERROR, null, exception);
    this.pendingLoginRequest = null;
    throw exception;
    }
    this is line no 382 place say how can start the LoginActivity??

    Reply
  28. hi man!… I emerged a mistake is that when runing the app does not open the LAYOUT where is the option to sign, that is only the MAIN ACTIVITY where i get nothing. I hope you can help me

    Reply
  29. hi i copied the code but iam not getting image when iam logged in.. Can you give me the code for that how to get the user image when logged into app..

    Reply
    • Hey aakriti….just change your logcat from verbose to debug…
      and then in search area wite key hash….you will get it (hash key) in logcat…
      Hope this will help u or anybody else 🙂

      Reply
  30. Hi, first thanks for the tutorial, its easy to follow and implement..
    i have a question…
    After successful login, how and where can i use intent to go other activity..
    For now, after login also coming back to LoginActivity. Can you please clear the doubt?

    Reply
  31. @Override
    public void onSuccess(LoginResult loginResult) {

    // Facebook Email address
    GraphRequest request = GraphRequest.newMeRequest(
    loginResult.getAccessToken(),
    new GraphRequest.GraphJSONObjectCallback() {
    @Override
    public void onCompleted(
    JSONObject object,
    GraphResponse response) {
    Log.v(“LoginActivity Response “, response.toString());

    try {
    Toast.makeText(getApplicationContext(), “Name ” + object.getString(“name”)
    +”\nEmail “+object.getString(“email”), Toast.LENGTH_LONG).show();

    } catch (JSONException e) {
    e.printStackTrace();
    }
    }
    });
    Bundle parameters = new Bundle();
    parameters.putString(“fields”, “id,name,email,gender, birthday”);
    request.setParameters(parameters);
    request.executeAsync();

    }

    Reply
  32. APK build is successful but am gointing java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.lang.Object.hashCode()’ on a null object reference error occur in catalog ..

    Reply
  33. I am a php developer, Now I want to develop android app. Get some suggesion & tutorial link from which I learn very fast. Please help

    Reply
    • @tom- main activity is automatically generated when you choose blank activity with fragment….you dont need to do any modifications to it for this code.
      Hope it helped you 🙂

      Reply
  34. i didn’t get output in mobile..when i click on login with Facebook it is loading and stopped, not shown login page in mobile.

    Reply
  35. Hi Sir, The app is not working for me i am not able to understand where to put code should i make
    1.fragment (Blank Fragment)
    2.MainActivity
    3.activity_main.xml
    4.fragment.xml
    what to put in MainActivity ??????
    Please answer
    Thank you

    Reply
  36. Hi I’m just learning android and found it interesting to perform the user login but I can not do this supplement shows me red line last one:

    It happens that I have MainActivityFragment and really in the tutorial nowhere shown or MainActivityFragment is added and the truth is that I can put donot to make it work.
    Thank you.

    Reply
  37. Hello, i have implemented the code below and its work but i have a probleme when i try to log with another facebook account.
    Please have you an idea to solve the problem ?

    Thank’s
    Reda

    Reply
  38. the login works for only developer, i.e., my id. why not for other.
    when others login from it, an error appears that app is in development mode

    Reply

Leave a Comment