Suleiman

App developer with an eye for design. Loves to create apps with good UI/ UX that doesn't annoy people. In his spare time, he likes to draw and paint.

You may also like...

  • Cristian Dregan

    Is there a way to get larger than 50×50 image?

  • Andrew Kurth

    hi, i dont understand where musername, memail, and mpermissions come from. I followed every step, but am getting errors. Please reply asap. What i am confused about is the fact that you do not define them anywhere before in your code.

  • AndroidMan

    How can I change all of my layout after the login?

  • AndroidMan

    Hi, first thanks for this tutorial. I’ve some questions:
    1. How can I redirect the user after login. I try put

    if(ParseUser.getCurrentUser() != null) {
    Intent intent = new Intent(getApplicationContext(), IndexActivity.class);
    startActivity(intent);
    }

    in onCreate method, but doesn’t work good.

  • Dominique Canlas

    Has anyone found a solution with regards to FB not returning all user details when requested? I verified my access token and that I have proper permissions. I am getting the name and fbId returned but not the email. Is it possible that it has something to do with app still in development mode or not released in the marketplace yet? Thanks for any response.

    • Dominique Canlas

      Update: Finally figured this out after hours of searching around in the FB docs. By default, the “/me” route only returns name and id. In order to get the email (or other fields), you have to explicitly request for it. You can just do:


      Bundle parameters = new Bundle();
      parameters.putString("fields", "email,name");

      Just include “parameters” in the GraphRequest arguments.
      Hope this helps anyone who is encountering the same problem!

    • Hey Dominique,
      Thats awesome! Good to see you got it solved. In the earlier versions, using the “/me” path fetched the email as well, but the new SDK requires you to pass that as a parameter.
      Thanks for helping out. Hopefully I’ll be updating the post today.

      Cheers!

      • Part 1 and 2 have now been updated to the new SDKs.

  • Michael Lorenz Jimenez- Labrad

    Thank you for the very useful tutorial. I have able to connect with parse and link it with fb. also I was able to fetch my profile pic and applied it in my app. But my problem is the part of getUserDetailsFromFB. I dont understand why I cant fetch my fb username and email.. I also added try catch in order to find the exception but it does not display any in logcat.. it only says in my app that “Welcome 9yreuyuynfjeuy….”.I believed that it didnt fetch any data in my fb. btw i am using fb sdk 4.7 and parse jar provided in the parse quick start. Any idea how to fix it?

    • this is the same problem I’m tackling with.
      hve you figured out the solution?

    • Hi Michael,
      You need to request for the email ID explicitly (Changes made in the new SDK). Check out Dominique’s reply.

  • bossdog22

    Great tutorial, really cleared things up for me. Problem I’m having now is I can’t retrieve user details from Facebook? At the very end of the getUserDetailsFromFB() method I put: System.out.println(“The email retrieved is ” + email + ” username is ” + name); in order to see what values are being returned. In the logcat both items are always null? Any ideas as to what I’m doing wrong?

    • Hey there,
      Happy to know the tutorial was useful. Which version of the SDK are you using? Please cross check against the part 1 setup against mine for me? If you still face problems, let me know.

      • bossdog22

        I have Parse-1.9.1.jar & ParseFacebookUtilsV4-1.9.1.jar. In the build.gradle I have compile ‘com.facebook.android:facebook-android-sdk:4.2.0. Should I compile a different version with those jars?

      • bossdog22

        Following what you did in part 1 but the problem remains. Compile ‘com.facebook.android:facebook-android-sdk:4.2.0’ is added to gradle with FacebookUtilsV4-1.9.1.jar in the libs folder…

      • To my knowledge, the current Facebook SDK is 4.7.0 and Parse would be updated as well. Please update relevant libraries first.

      • Posts have been updated to use the latest SDKs!

  • This tutorial isn’t working for me, bro!!! 🙁

    I’m unable to fetch anything from facebook.

    • That doesn’t tell me anything with which I can help you with.

      • Hello.
        The error I’m getting:

        “crash in the same process: AsyncTask #2

        java.lang.RuntimeException: An error occured while executing doInBackground()

        at android.os.AsyncTask$3.done(AsyncTask.java:304)

        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)

        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)

        at java.util.concurrent.FutureTask.run(FutureTask.java:242)

        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

        at java.lang.Thread.run(Thread.java:818)

        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.net.Uri com.facebook.Profile.getProfilePictureUri(int, int)’ on a null object reference

        at com.humanehelper.humanehelper.SignUpScreen$ProfilePhotoAsync.doInBackground(SignUpScreen.java:322)

        at com.humanehelper.humanehelper.SignUpScreen$ProfilePhotoAsync.doInBackground(SignUpScreen.java:311)

        at android.os.AsyncTask$2.call(AsyncTask.java:292)

        at java.util.concurrent.FutureTask.run(FutureTask.java:237)”

        My code:

        class ProfilePhotoAsync extends AsyncTask {
        Profile profile;
        public Bitmap bitmap;

        public ProfilePhotoAsync(Profile profile) {
        this.profile = profile;
        }

        @Override
        protected String doInBackground(String… params) {
        // Fetching data from URI and storing in bitmap
        bitmap = DownloadImageBitmap(profile.getProfilePictureUri(200, 200).toString());

        return null;
        }

        @Override
        protected void onPostExecute(String s) {
        super.onPostExecute(s);
        mProfileImage.setImageBitmap(bitmap);
        }
        }

        public static Bitmap DownloadImageBitmap(String url) {
        Bitmap bm = null;
        try {
        URL aURL = new URL(url);
        URLConnection conn = aURL.openConnection();
        conn.connect();
        InputStream is = conn.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        bm = BitmapFactory.decodeStream(bis);
        bis.close();
        is.close();
        } catch (IOException e) {
        Log.e(“IMAGE”, “Error getting bitmap”, e);
        }
        return bm;
        }

        Please help with this.
        THANKS!

      • Check the updated posts

      • the problem I am encountering is that this code is not fetching user’s proper name for ex- my name is ‘Hammad Nasir’ but the name it is fetching and displaying is ‘CZ6K9iirFRUlfVW8PEWzpDgvV’. Another problem is that it is not fetching the email & profile picture.
        Please help with this.

      • Lai

        same problem here. I think there are some codes missing. I ran your github codes as is and failed to get anything from facebook. But the user is able to login to facebook. Please help!

      • Hi there,
        Both part 1 & 2 of this post has been updated with the latest SDKs. Please revisit them and do the changes to get it working.
        Thanks.

      • Lai

        Profile picture is not saving in Parse :(((
        Also the username retrieved from Parse is not their name.

      • Lai

        getUserDetailsFromFB is not working. Can i send u my codes thru email?

      • Hi there,
        I’ve checked to make sure it works with the latest SDKs. You might want to go through part 1 and see if you’re using the correct versions.

        PS: All imports are now through Gradle. (No JARs)

      • Lai

        I think I know what the problem is. 🙂 When I run this on Mac, it runs perfectly well. But on windows, profile picture is not saving in Parse :(((

        Also the username retrieved from Parse is not their name.

  • Rama Srinivas

    Thank you for your post

    But for me the following part of the code is not executing

    public void onCompleted(GraphResponse response) {
    /* handle the result */
    try {
    email = response.getJSONObject().getString(“email”);
    mEmailID.setText(email);
    Log.d(“Email”, email);
    name = response.getJSONObject().getString(“name”);
    mUsername.setText(name);
    Log.d(“Name”, name);

    saveNewUser();
    } catch (JSONException e) {
    e.printStackTrace();
    }
    }

    • Hi Rama,
      Is that part of the code not being executed AT ALL, or is there some kind of error? Could you cross check your code against mine once?

      • Rama Srinivas

        Hi Suleiman,

        I had tried a lot the code is getting executed. But the problem is that If I am giving the “email” permission but I not able to retrieve the email Id. In my Json response I am only obtaining “id” and “name” parameters. So from the try block in the following line the code is going to catch block.

        email = response.getJSONObject().getString(“email”);

        Due to no “email” parameter.

        Now I need to fetch the email Id of the user. so please help me out.

      • Before trying to fetch ’email’ I’d print the response to the logs, to see what I’m getting first.

  • This is not working for me, bro! 🙁

  • Mostafa Anter

    thanx for best tutorial ,

    i have one issues why you you use saveNewUser()??? parse SDK receives the user’s Facebook access data and saves it to a ParseUser. If no ParseUser exists with the same Facebook ID, then a new ParseUser is created.

    • Unfortunately, I’m not aware of the recent developments with Parse. But at the time of writing, I had to manually save those details as a new ParseUser.

  • Mostafa Anter

    thanx for great tutorial

  • Ecstasy

    Thanks for the great post.

    I have few issues with the code. Could you please help me with this error in my logcat
    sendUserActionEvent() mView == null

    I am unable to retrieve my facebook profile picture, name and email.

    • I’m afraid just that one line won’t help me in identifying the error. If you’ve gone though my post carefully, I have mentioned how to retrieve all 3 values.

      • Ecstasy

        I had been closely going through the whole code many times but I think I have a problem with getUserDetailsFromFB() function as I am not able to retrieve any user information as a username I am getting a long string as shown in the attachment. Please help me resolve this matter as I am new to both Android and Parse.

      • Have you setup the SDK properly? I’ve gone over this in great detail in Part 1. Make sure that is properly configured first.

      • Ecstasy

        I have rechecked the whole procedure but still getting the same thing. Could you please tell me if there is something to do with facebook permissions?

        I want to show you my logcat as well. Please help me resolve this matter.

      • Do post your error log, so I could take a look?

      • Ecstasy

        Here’s my logcat

        09-12 04:40:25.893 13730-13730/? I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
        09-12 04:40:25.898 13730-13730/? I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_GT-N7100_4.4.2_0035
        09-12 04:40:25.898 13730-13730/? I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
        09-12 04:40:25.903 13730-13730/? D/dalvikvm﹕ Late-enabling CheckJNI
        09-12 04:40:27.598 13730-13730/package name W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
        09-12 04:40:27.598 13730-13730/package name I/dalvikvm﹕ Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
        09-12 04:40:27.598 13730-13730/package name W/dalvikvm﹕ VFY: unable to resolve interface method 14281: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
        09-12 04:40:27.598 13730-13730/package name D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
        09-12 04:40:27.598 13730-13730/package name I/dalvikvm﹕ Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
        09-12 04:40:27.598 13730-13730/package name W/dalvikvm﹕ VFY: unable to resolve interface method 14285: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
        09-12 04:40:27.598 13730-13730/package name D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
        09-12 04:40:27.653 13730-13730/package name I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
        09-12 04:40:27.653 13730-13730/package name W/dalvikvm﹕ VFY: unable to resolve virtual method 485: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
        09-12 04:40:27.653 13730-13730/package name D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
        09-12 04:40:27.653 13730-13730/package name I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
        09-12 04:40:27.653 13730-13730/package name W/dalvikvm﹕ VFY: unable to resolve virtual method 507: Landroid/content/res/TypedArray;.getType (I)I
        09-12 04:40:27.653 13730-13730/package name D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
        09-12 04:40:27.733 13730-13730/package name D/KeyHash:﹕ Keyhash=
        09-12 04:40:27.888 13730-13730/package name D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
        09-12 04:40:27.903 13730-13730/package name D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
        09-12 04:40:27.908 13730-13730/package name D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
        09-12 04:40:27.913 13730-13730/package name E/﹕ Device driver API match
        Device driver API version: 29
        User space API version: 29
        09-12 04:40:27.913 13730-13730/package name E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Tue Jul 22 19:59:34 KST 2014
        09-12 04:40:28.023 13730-13730/package name D/OpenGLRenderer﹕ Enabling debug mode 0
        09-12 04:42:50.308 13730-13730/package name V/WebViewChromium﹕ Binding Chromium to the background looper Looper (main, tid 1) {424d6990}
        09-12 04:42:50.318 13730-13730/package name I/chromium﹕ [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
        09-12 04:42:50.323 13730-13730/package name I/BrowserProcessMain﹕ Initializing chromium process, renderers=0
        09-12 04:42:50.388 13730-15155/package name W/chromium﹕ [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
        09-12 04:42:50.453 13730-13730/package name I/dalvikvm-heap﹕ Grow heap (frag case) to 11.736MB for 1127536-byte allocation
        09-12 04:42:51.238 13730-15176/package name I/chromium﹕ [INFO:simple_index_file.cc(397)] Simple Cache Index is being restored from disk.
        09-12 04:42:51.338 13730-13730/package name D/ProgressBar﹕ updateDrawableBounds: left = 0
        09-12 04:42:51.338 13730-13730/package name D/ProgressBar﹕ updateDrawableBounds: top = 0
        09-12 04:42:51.338 13730-13730/package name D/ProgressBar﹕ updateDrawableBounds: right = 96
        09-12 04:42:51.338 13730-13730/package name D/ProgressBar﹕ updateDrawableBounds: bottom = 96
        09-12 04:42:52.038 13730-15177/package name D/dalvikvm﹕ GC_FOR_ALLOC freed 1533K, 21% free 10409K/13108K, paused 25ms, total 25ms
        09-12 04:42:55.528 13730-13730/package name E/ViewRootImpl﹕ sendUserActionEvent() mView == null
        09-12 04:42:55.568 13730-13730/package name I/chromium﹕ [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
        09-12 04:42:55.603 13730-13730/package name I/chromium﹕ [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
        09-12 04:42:56.243 13730-13730/package name D/dalvikvm﹕ GC_FOR_ALLOC freed 587K, 22% free 10287K/13108K, paused 15ms, total 15ms
        09-12 04:42:56.243 13730-13730/package name I/dalvikvm-heap﹕ Grow heap (frag case) to 11.329MB for 153680-byte allocation
        09-12 04:42:56.258 13730-13730/package name D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 22% free 10436K/13260K, paused 13ms, total 13ms
        09-12 04:43:12.703 13730-13730/package name E/ViewRootImpl﹕ sendUserActionEvent() mView == null
        09-12 04:43:14.998 13730-13730/package name E/ViewRootImpl﹕ sendUserActionEvent() mView == null
        09-12 04:43:15.758 13730-15438/package name D/dalvikvm﹕ GC_FOR_ALLOC freed 1018K, 23% free 10365K/13412K, paused 17ms, total 17ms
        09-12 04:43:16.958 13730-13730/package name D/MyApp﹕ User logged in through Facebook!
        09-12 04:43:16.968 13730-13730/package name W/System.err﹕ java.lang.NullPointerException
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at package name.MainActivity.getUserDetailsFromParse(MainActivity.java:193)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at package name.MainActivity.access$100(MainActivity.java:55)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at package name.MainActivity$2$1.done(MainActivity.java:115)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at package name.MainActivity$2$1.done(MainActivity.java:104)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:107)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:733)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at android.os.Looper.loop(Looper.java:146)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5602)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
        09-12 04:43:16.973 13730-13730/package name W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
        09-12 04:43:16.978 13730-13730/package name W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        09-12 04:43:16.978 13730-13730/package name W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        09-12 04:43:16.978 13730-13730/package name W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)

      • From the looks of it, your user is able to log in through Facebook but you’re having trouble retrieving the saved details from Parse.
        Check if you have this line.

        parseUser = ParseUser.getCurrentUser();
        I suspect your current user is going null somewhere, so do a check before calling it in.
        Also, after fetching your username from Facebook and before saving it, try dumping the username to the logs to see what it is. So you’ll know if you’re actually fetching the right username or just garbage.

      • Ecstasy

        I am unable to post my logcat here as it requires a permission to be pasted here.
        What exactly is happening now that whenever the user logs in first time it only shows his profile picture without username and email. The next time user returns to the app it only shows a long string as a username without profile picture and and email. Can’t figure out what actually happening there. Your assistance would be a great help.

      • Please use StackOverflow and post the error along with relevant code snippet there. That way I can take a look and help you out.

  • Jack

    ParseFacebookUtils.logInWithReadPermissionsInBackground method always return a null user
    what is the problem 🙁

    • logInWithReadPermissionsInBackground() will throw a ParseException via done(). Try to catch that exception and see what error it is. That will help find your issue.

  • Firas

    Thanks its amazing post part1 and 2
    just about profile image :

    ProfilePhotoAsync profilePhotoAsync = new ProfilePhotoAsync(mFbProfile);
    profilePhotoAsync.execute();

    what is mFbProfile and from where i can get it

    • If you go through my GitHub project, you can see that ‘mFbProfile’ is an object of com.facebook.Profile.
      I pass this to my AsyncTask’s constructor so I can use it to fetch my profile photo from Facebook.

Subscribe to stay updated
You'll be first to know about new articles and more. They're sent straight to your inbox!
No Spam, no BS. Promise. You can unsubscribe anytime.
Gradle setup, ProGuard rules, Material Design palette, metrics and much more

FREE Material Design Starter Project

For more details, click on the below link.
GET IT NOW FOR ANDROID STUDIO!
Download FREE
STARTER PROJECT
Material Design Template Project for Android Studio
DOWNLOAD STARTER PROJECT
Android O is finally here!
Ready your Apps to get an advantage on Play Store.