I am using this method to perform a Facebook login without using the fb button Facebook authentication without login button
It\'s working fine, but a progress bar wi
Simple solution just show progressbar in registercallback
See my code
fb_login.registerCallback(callbackManager, new FacebookCallback() {
@Override
public void onSuccess(LoginResult loginResult) {
progressBar.setVisibility(View.VISIBLE);
// App code
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
Log.v("Profile --------- ", response.toString());
progressBar.setVisibility(View.GONE);
try {
if (object!=null){
F_ID = object.getString("id");
if (object.has("first_name"))
Name = object.getString("name");
Log.d(TAG, "onCompleted: Name - "+object.getString("name"));
if (object.has("last_name"))
LastName = object.optString("last_name");
Log.d(TAG, "onCompleted: LastName - "+object.optString("last_name"));
if (object.has("email"))
Email = object.optString("email");
if (object.has("birthday"))
DOB = object.optString("birthday");
ProfilePic = "https://graph.facebook.com/" + F_ID + "/picture?type=large";
Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("Name", object.getString("name"));
intent.putExtra("Email", Email);
intent.putExtra("DOB", DOB);
intent.putExtra("ID", F_ID);
intent.putExtra("ImgURL", ProfilePic);
Log.d(TAG, "onCompleted: Email = "+Email+" Name = "+Name+" FID = "+F_ID);
//sharedpreference is used to store the email, password and the useername
SharedPreferenceManager.setDefaults("email", Email, SigninActivity.this);
SharedPreferenceManager.setDefaults("facebook_id", F_ID, SigninActivity.this);
SharedPreferenceManager.setDefaults("profile_pic", "https://graph.facebook.com/" + F_ID + "/picture?type=large", SigninActivity.this);
if (object.has("name"))
SharedPreferenceManager.setDefaults("username", Name, SigninActivity.this);
Log.d(TAG, "onCompleted: Store shared data");
startActivity(intent);
}else
Log.d(TAG, "onCompleted: object is null "+object);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
System.out.println("Facebook Login Successful!");
System.out.println("Logged in user Details : ");
System.out.println("--------------------------");
System.out.println("User ID : " + loginResult.getAccessToken().getUserId());
System.out.println("Authentication Token : " + loginResult.getAccessToken().getToken());
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), "Login cancelled by user!", Toast.LENGTH_LONG).show();
System.out.println("Facebook Login Cancel!!");
}
@Override
public void onError(FacebookException e) {
Toast.makeText(getApplicationContext(), "Something went wrong!!", Toast.LENGTH_LONG).show();
System.out.println("Facebook Login failed!! because of " + e.getCause().toString());
}
});