Integrate Facebook Login with Parse – Part 2
If you’ve managed to survive Part 1, then welcome to Part 2 of the post! Here we’ll look at actually integrating Facebook login with Parse. We’ll fetch needed details from Facebook, sign up the user with Parse and store those details.
In the previous part, we focused solely on getting Parse and Facebook SDK integrated in our apps, which by in itself was no ordinary feat. Now let’s dive into our app and get these things to work.
Why Social Sign In?
The very fact that why we opt for a social login is to provide a richer login experience. The user already has his registered credentials on Facebook. We can use that do validate an existing user, rather than asking him to manually fill input fields. This is tedious on the user’s part, which can be avoided.
Moreover we can optionally pull other relevant data, which we can utilize to provide a richer user experience.
Create a Login Experience
The reason why I’ve purposely labelled it a login ‘experience’ which in short is your login screen, is because this is where users get to see your app for the first time, and if they don’t like it now, they’re probably never going to return. This is the very first screen your user will see and I strongly you spend ample time creating a good signup screen. Here’s mine:
But for practice purposes, just a button would do for now. This button on click, will log in the user via Facebook.
Facebook Login
mBtnFb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ParseFacebookUtils.logInWithReadPermissionsInBackground(MainActivity.this, mPermissions, new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { if (user == null) { Log.d("MyApp", "Uh oh. The user cancelled the Facebook login."); } else if (user.isNew()) { Log.d("MyApp", "User signed up and logged in through Facebook!"); getUserDetailsFromFB(); } else { Log.d("MyApp", "User logged in through Facebook!"); getUserDetailsFromParse(); } } }); } });
The logInWithReadPermissionsInBackground is what we’ll use to log in the user. We must supply a list of permissions to this method. This is akin to an AsyncTask. The LogInCallback provides a done() method. This is essentially what you must do upon log in completion.
The 3 if conditions are clearly denoted by their respective Log tags. Upon logging in for the very first time, the app will redirect you to a Facebook screen where he/ she must consent that your app requires their Facebook information. After this we’re back to our app. So now, you might want to take the user to your home screen with a successful Toast message! Alternatively, if it get’s cancelled you should handle the error.
New Users
user.isNew()
helps us identify that a new user is signing up. So after they log in via Facebook, we will retrieve their profile photo, name and email from Facebook. Then we will save those details to Parse.
The getUserDetailsFromFB() method will help in fetching our Facebook data.
private void getUserDetailsFromFB() { // Suggested by https://disqus.com/by/dominiquecanlas/ Bundle parameters = new Bundle(); parameters.putString("fields", "email,name,picture"); new GraphRequest( AccessToken.getCurrentAccessToken(), "/me", parameters, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ try { email = response.getJSONObject().getString("email"); mEmailID.setText(email); name = response.getJSONObject().getString("name"); mUsername.setText(name); JSONObject picture = response.getJSONObject().getJSONObject("picture"); JSONObject data = picture.getJSONObject("data"); // Returns a 50x50 profile picture String pictureUrl = data.getString("url"); new ProfilePhotoAsync(pictureUrl).execute(); } catch (JSONException e) { e.printStackTrace(); } } } ).executeAsync(); }
As you can see, in essence this method will be responsible for executing 2 AsyncTasks:
- GraphRequest – to fetch user name and email
- AsyncTask (native) – to download profile photo and display on ImageView
The GraphRequest can help us fetch all sorts of data from Facebook. It requires some time understanding how it works, so I suggest you go through.
The GraphResponse returns back JSON data which we can use to retrieve our required information. If you’re unfamiliar with JSON parsing and how it works on Android, you can follow this brilliant post on AndroidHive that explains it brilliantly.
However, that’s only if you’re interested in learning more. For the purposes of this post, you can just copy over my code snippet and it will work just fine 🙂
saveNewUser()
If you noticed carefully, we call this method in the onCompleted() method of our GraphRequest. Why because, this method indicates what must be done upon completing the fetch request. This means that the requested data has been fetched. So once that is done, we can safely store our data in Parse. Doing so before might result in a crash!
Alternatively, see the AsyncTask where we download our profile photo. If this takes longer to execute, then our saveNewUser() will still fail. Know why? We’re attempting to download the photo while the AsyncTask may still be executing. If your AsyncTask takes a while, then again the app would crash.
I have purposely done it this way to highlight the various issues when tasks execute in parallel. The fail safe way would be to call saveNewUser() in your AsyncTask’s onPostExecute() method.
private void saveNewUser() { parseUser = ParseUser.getCurrentUser(); parseUser.setUsername(name); parseUser.setEmail(email); // Saving profile photo as a ParseFile ByteArrayOutputStream stream = new ByteArrayOutputStream(); Bitmap bitmap = ((BitmapDrawable) mProfileImage.getDrawable()).getBitmap(); bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream); byte[] data = stream.toByteArray(); String thumbName = parseUser.getUsername().replaceAll("\\s+", ""); final ParseFile parseFile = new ParseFile(thumbName + "_thumb.jpg", data); parseFile.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { parseUser.put("profileThumb", parseFile); //Finally save all the user details parseUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { Toast.makeText(MainActivity.this, "New user:" + name + " Signed up", Toast.LENGTH_SHORT).show(); } }); } }); }
saveInBackground(), evident by the method (Yep you guessed it!) is used to save our user details to Parse via an AsyncTask. You can optionally have a SaveCallback if you want to do anything after a successful save. I’ve just showed a simple Toast notifying the user he signed up.
The ParseUser class is used to fetch information from Parse related to the user, which we have defined globally and initialize only when needed. We set our user’s email and username from what we retrieved from Facebook. Then we save our downloaded Facebook profile photo Bitmap as a ParseFile.
Note how I’m saving this file. I dynamically create the thumbnail’s file name based off the username. ‘profileThumb’ is a column which will automatically be created in our User class if it doesn’t exist.
Profile Photo AsyncTask
Create a new class called ProfilePhotoAsync and make it extend AsyncTask. Now I’m not going too in depth about what these are for the post’s sake.
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
In short, any task that will take time to execute or its duration to finish is unknown. If it risks stalling the UI making the app non responsive, then AsyncTask is your solution. This is exactly what we’ll use to download our profile photo from Facebook.
class ProfilePhotoAsync extends AsyncTask<String, String, String> { public Bitmap bitmap; String url; public ProfilePhotoAsync(String url) { this.url = url; } @Override protected String doInBackground(String... params) { // Fetching data from URI and storing in bitmap bitmap = DownloadImageBitmap(url); return null; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); mProfileImage.setImageBitmap(bitmap); saveNewUser(); } }
The brunt of your work must be done in the doneInBackground() method, which is why we’re handling the actual download there. After your task is complete, what is be done next must come in the onPostExecute() method. When this method enters, our download task would be complete. So now we can set our downloading bitmap to our ImageView.
DownloadImageBitmap()
We’ll use this handy utility method to handle our download. We simply pass a URL as a parameter to this method, which will return a Bitmap at the end.
NOTE: Network operations must be run off the UI thread!
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; }
Whoa! That was really long. Let’s take a breather here and look at what we’ve done so far. Up till now we’ve seen how to handle a NEW user. Fetched relevant details and photo from Facebook and saved it to Parse.
Just make sure you’re testing this app on a REAL device so we have internet and Facebook to work with.
LG Nexus 5 is said to be the best device for this by many. Do run the app just ONCE. Log in and you will get a Toast saying you signed up.
Great! Back to the post. We’ll now show a Welcome back Toast if its a returning user that logs in.
This is what your Parse panel should show you, after successfully running it once. There is now one new entry in your User class. Note all the relevant details from your Facebook fed into your Parse backend.
Returning User
We will simply fetch 3 data from Parse: name, email and profile photo (which we saved to a ParseFile).
private void getUserDetailsFromParse() { parseUser = ParseUser.getCurrentUser(); //Fetch profile photo try { ParseFile parseFile = parseUser.getParseFile("profileThumb"); byte[] data = parseFile.getData(); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); mProfileImage.setImageBitmap(bitmap); } catch (Exception e) { e.printStackTrace(); } mEmailID.setText(parseUser.getEmail()); mUsername.setText(parseUser.getUsername()); Toast.makeText(MainActivity.this, "Welcome back " + mUsername.getText().toString(), Toast.LENGTH_SHORT).show(); }
The email and username is fetched after initializing ParseUser and directly passed on to our TextViews. The ParseFile is retrieved via parseUser by specifying the ‘key’ (column name in the table).
However, simply retrieving the file will not suffice so we basically have to undo the file conversion steps we did while storing the Bitmap into a ParseFile. Here, we have to reconstruct the Bitmap from the ParseFile data. Finally after all that, display a Toast welcoming back the user!
Finally run the app now (second time) and log in via Facebook. You will see our name, email and profile photo appearing. Nothing new same as last time, but as developers, we know that only this time, the data which was earlier saved in Parse, is now being retrieved. 🙂
End Result
I know the post has been long without any visual result. But finally here’s an output you all can feast your eyes on!
Do ignore the grey rectangle in the middle. That’s just me doing a miserable job of trying to hide my email 😉 Also note that the Facebook confirmation screen for you will look different (better and faster). I’m using an emulator (which sucks).
You can also check out this code sample on GitHub. Just be sure to replace your Facebook AppID, Parse Application ID and Client Key in values/strings.xml.
Great. Now go ahead and jump in joy as you’re done with this long post. Don’t forget to Follow @Suleiman_194 and subscribe (below) for instant updates!
Product Designer who occasionally writes code.
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.
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.
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?
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.
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.
Profile picture is not saving in Parse :(((
Also the username retrieved from Parse is not their name.
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)
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.
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?
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! 🙁
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.
thanx for great tutorial
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.
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.
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?
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.
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.
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.
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.