Can't perform authentication through facebook with Parse

643 views Asked by At

I want to perform authentication with facebook,using Parse to store user's information. I got the following code in my application class :

public class App extends Application {    
    public void onCreate() {
        super.onCreate();
        Parse.enableLocalDatastore(this);
        Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
        Parse.initialize(this, "[XXX]", "[XXX]");
        ParseFacebookUtils.initialize(this);
    }
}

And in my login activity the following :

public class LoginActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        findViewById(R.id.login_auth_button).setOnClickListener(authClickListener);
    }
    @Override
    protected void onStart() {
        super.onStart();
        currentUser = ParseUser.getCurrentUser();
        if (currentUser != null) {
            loadNext();
        } else {
        }
    }

    public void loadNext(){
        [XXX]
    }

    View.OnClickListener authClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            List<String> permissions = Arrays.asList("public_profile","user_friends");
ParseFacebookUtils.logInWithReadPermissionsInBackground(LoginActivity.this, permissions, new LogInCallback() {
                @Override
                public void done(ParseUser user, ParseException err) {
                    if(err!=null)
                        err.printStackTrace();
                    if (user == null) {
                        Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
                    }
                    else {
                        loadNext();
                    }
                }
            });

        }
    };
}

Everything seems to be correctly configured (if I create a TestObject with Parse, I can see it in Parse Dashboard). When I click on the login button, Facebook activity is launched, I can authorize my app to have access to facebook, but when I agree, nothing happens, loadNext() is never called, and I got nothing in the log about it. If I click again on the button, I got the following exception :

06-08 22:23:46.542    8722-8722/pics.pickd.pickd W/System.err﹕ com.parse.ParseException: java.lang.RuntimeException: Unable to authenticate when another authentication is in process
06-08 22:23:46.542    8722-8722/pics.pickd.pickd W/System.err﹕ at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:105)
06-08 22:23:46.542    8722-8722/pics.pickd.pickd W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
06-08 22:23:46.542    8722-8722/pics.pickd.pickd W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
06-08 22:23:46.542    8722-8722/pics.pickd.pickd W/System.err﹕ at android.os.Looper.loop(Looper.java:135)

Any idea ???

1

There are 1 answers

1
Blusky On BEST ANSWER

I found the answer. I missed to add a onActivityResult() method on my activity :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}