0
When the user presses the "login with facebook" button for the first time, the application asks for permission and returns the "Gave" dialog, however if I login and try to login again error appears, then I have to delete the permission in the application to be able to do again, how do I check if the user has already registered once?
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.AccessToken;
import com.facebook.AccessTokenTracker;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
public class LoginFacebook extends Fragment {
private LoginButton loginButton;
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private AccessToken accessToken;
private Fragment1 fragment1;
@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getContext());
callbackManager = CallbackManager.Factory.create();
final View view = inflater.inflate(R.layout.loginfacebook, container, false);
loginButton = (LoginButton) view.findViewById(R.id.loginfacebook);
loginButton.setReadPermissions("email");
// If using in a fragment
loginButton.setFragment(this);
// Other app specific specialization
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
dlg.setMessage("deu"+loginResult.getAccessToken().getUserId());
dlg.setNeutralButton("ok",null);
dlg.show();
}
@Override
public void onCancel() {
AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
dlg.setMessage("cancelou");
dlg.setNeutralButton("ok",null);
dlg.show();
}
@Override
public void onError(FacebookException exception) {
AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
dlg.setMessage("deu erro");
dlg.setNeutralButton("ok",null);
dlg.show();
}
});
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
// Set the access token using
// currentAccessToken when it's loaded or set.
}
};
// If the access token is available already assign it.
accessToken = AccessToken.getCurrentAccessToken();
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
Send the stack of error :D
– Carlos Bridi
Login error: there is an error in logging you into this application, Please Try Again later
– Diego Noceli
I usually save the login data in Sharedpreferences, basically if the value is there is why you are logged in. Another thing that move is in the facebook button or Voce takes the data of the face and uses a login own?
– Neuber Oliveira
It would be just like login of the same face, I just need the same id to use as a primary key, but how do I fix this my error of erasing the application permission by Facebook?
– Diego Noceli