2
votes

I am having problem with facebook login in my cn1 app. I followed all the instructions given here: http://www.codenameone.com/facebook-login.html. I create a new instance of FacebookConnect then I set the clientId, secret etc. Then I set a LoginCallback and call doLogin(). However when I tried to run it on my device the screen just loads and it never stops. It doesn't even call LoginFailed. It just never stopped loading.

Here is my code:

faceBookButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        fb.setClientId("XXXXXXXXXXXXXXXX");
        fb.setClientSecret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        fb.setRedirectURI("");
        fb.setCallback(new LoginCallback(){
            @Override
            public void loginFailed(String errorMessage) {
                Dialog dg = new Dialog();
                dg.setDisposeWhenPointerOutOfBounds(true);
                dg.setTitle("Login succeeded");
                dg.show();
            }

            @Override
            public void loginSuccessful() {
                 String token = fb.getAccessToken().getToken();
                 Dialog dg = new Dialog();
                 dg.setDisposeWhenPointerOutOfBounds(true);
                 dg.setTitle("Login succeeded");
                 dg.show();
            }
        });
        fb.doLogin();
    }
});  
1
is this working on the simulator? why the redirectURI is empty? did you added the relevant build hints? - Chen
@Chen I added a URI and the permissions. Now it is opening the login form and allowing me to enter my username and password. However once I log in it opens the webpage of my URL in the app with a "Cancel" command at the top left. When I hit cancel it cancels the request to log in. How do I make it log straight in. I don't want it to open the Webpage of my URL. If it has to. Then what do I do to allow the user to continue without pressing cancel and cancelling the request. - Kyri33
Make sure the redirectURI is configured on your fb app(on their portal) and on the Simulator upon login success you will see this page briefly (just a simulator thing) before the login succeed. On devices you won't even get the login screen, it suppose to log you in with the native fb app - Chen

1 Answers

0
votes

Check out the full guide on facebook login here.

On login success you need to show a new Form and not a Dialog as you are moving away from the login screen of your application. There is a full end to end sample in the chat tutorial.