Facebook connection, display problem

84 views
Skip to first unread message

usabg...@gmail.com

unread,
Aug 21, 2016, 2:23:10 PM8/21/16
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device

Hello everybody,

I have a display problem with my facebookConnection. I have a connection class with inscription class. with my app, it's possible to use the facebook connection.
But when i click the facebook button in order to load the home page when the connection has success, i see nothin after the facebook login ( fb.doLogin () ) . 

b_fcb.addActionListener((e) -> {
            String clientId = "xxxxxxxxxxxxxxxxxx";
            String redirectURI = "https://www.facebook.com/";
            String clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            Login fb = FacebookConnect.getInstance();
            fb.setClientId(clientId);
            fb.setRedirectURI(redirectURI);
            fb.setClientSecret(clientSecret);
            Log.p("1");
//            System.out.println("token = "+fb.getAccessToken());
            fb.setCallback(new LoginCallback() {
                @Override
                 public void loginSuccessful() {
                     /*InfiniteProgress ip = new InfiniteProgress();
                    ip.setUIID("InfiniteProgress");
                    final Dialog d = ip.showInifiniteBlocking();*/

                    Preferences.set("token", fb.getAccessToken().getToken());
                    final FacebookData data = new FacebookData();
                    data.fetchData(Preferences.get("token", (String) null), () -> {
                        Display.getInstance().callSerially(new Runnable() {
                            public void run() {
                                Dialog.show("Bravo ", "Bienvenu " + data.getName(), "OK", null);
                                manager.cheminPhoto = data.getImage();
                                manager.fcbLog = data.getName();
                                manager.isFcb = true;
                                manager.setLogin(data.getName());
                                manager.lanceFcbInsc();
                            }
                        });

                    });

b_fcb.addActionListener((e) -> {
            String clientId = "xxxxxxxx...xxxxxx";
            String redirectURI = "https://www.facebook.com/";
            String clientSecret = "xxxxxx...xxxxxxxxxx";
            Login fb = FacebookConnect.getInstance();
            fb.setClientId(clientId);
            fb.setRedirectURI(redirectURI);
            fb.setClientSecret(clientSecret);
            Log.p("1");
            fb.setCallback(new LoginCallback() {
                @Override
                 public void loginSuccessful() {
                     /*InfiniteProgress ip = new InfiniteProgress();
                    ip.setUIID("InfiniteProgress");
                    final Dialog d = ip.showInifiniteBlocking();*/

                    Preferences.set("token", fb.getAccessToken().getToken());
                    final FacebookData data = new FacebookData();
                    data.fetchData(Preferences.get("token", (String) null), () -> {
                        Display.getInstance().callSerially(new Runnable() {
                            public void run() {
                                Dialog.show("Bravo ", "Bienvenu " + data.getName(), "OK", null);
                                manager.cheminPhoto = data.getImage();
                                manager.fcbLog = data.getName();
                                manager.isFcb = true;
                                manager.setLogin(data.getName());
                                manager.lanceFcbInsc();
                            }
                        });

                    });
                 
                    // i launch the home page because of loginSuccessful
                    manager.lanceListeEvents("Ville");
                 }

                 @Override
                 public void loginFailed(String errorMessage) {
                     Form ff = new Form("Echec de connection", new BoxLayout(BoxLayout.Y_AXIS));
                     Label l = new Label("Erreur de connection facebook");
                     ff.addComponent(l);
                     ff.show();
                 }
             });
             
             //trigger the login if not already logged in
             if (!fb.isUserLoggedIn()) {
                 fb.doLogin();
             } else {
                 //get the token and now you can query the facebook API
                String token = fb.getAccessToken().getToken();
            }
        });

please help me.

Shai Almog

unread,
Aug 22, 2016, 12:00:41 AM8/22/16
to CodenameOne Discussions, usabg...@gmail.com
Hi,
that's not how facebook login works. Native/App login is different from website login. Those are VERY different things.

To use Facebook you need to use the graph API with the received token see https://www.codenameone.com/blog/building-a-chat-app-with-codename-one-part-3.html

usabg...@gmail.com

unread,
Aug 22, 2016, 8:41:48 AM8/22/16
to CodenameOne Discussions, usabg...@gmail.com
Sorry, i'hve forget to put my facebookData class, and interface UserData. I have done like this tuto, but i don't know where is the problem.
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controleur;

import com.codename1.io.ConnectionRequest;
import com.codename1.io.JSONParser;
import com.codename1.io.NetworkManager;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;

/**
 *
 * @author PC
 */
public class FacebookData implements UserData {
        String name;
        String id;

        @Override
        public String getName() {
            return name;
        }

        @Override
        public String getId() {
            return id;
        }

        @Override
        public String getImage() {
            return "https://graph.facebook.com/v2.7/"+id+"/picture";
        }

        @Override
        public void fetchData(String token, Runnable callback) {
            ConnectionRequest req = new ConnectionRequest() {
                protected void readResponse(InputStream input) throws IOException {
                    JSONParser parser = new JSONParser();
                    Map<String, Object> parsed = parser.parseJSON(new InputStreamReader(input, "UTF-8"));
                    name = (String) parsed.get("name");
                    id = (String) parsed.get("id");
                }

                @Override
                protected void postResponse() {
                    callback.run();
                }

                @Override
                protected void handleErrorResponseCode(int code, String message) {
                    //access token not valid anymore
                    if(code >= 400 && code <= 410){
                        //doLogin(FacebookConnect.getInstance(), FacebookData.this, true);
                        /*Hashtable meta = new Hashtable();
                                meta.put(com.codename1.push.Push.GOOGLE_PUSH_KEY,
                                    1276);*/
                        return;
                    }
                    super.handleErrorResponseCode(code, message);
                }
            };
            req.setPost(false);
            req.setUrl("https://graph.facebook.com/v2.7/me");
            req.addArgumentNoEncoding("access_token", token);
            NetworkManager.getInstance().addToQueue(req);
        }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controleur;

/**
 *
 * @author PC
 */
public interface UserData {
    public String getName();
    public String getId();
    public String getImage();
    public void fetchData(String token, Runnable callback);
}


usabg...@gmail.com

unread,
Aug 22, 2016, 8:44:44 AM8/22/16
to CodenameOne Discussions, usabg...@gmail.com
I have my hashkey and my facebook login count: https://developers.facebook.com/apps/

Shai Almog

unread,
Aug 23, 2016, 1:28:42 AM8/23/16
to CodenameOne Discussions, usabg...@gmail.com
If you have your login you can now use the Facebook Graph API webservice to query facebook.

usabg...@gmail.com

unread,
Aug 23, 2016, 11:31:34 AM8/23/16
to CodenameOne Discussions, usabg...@gmail.com
yes i know that, my facebook queries worked before, but know, i thing that i have all, and my code it's complete. But when  push facebook button in order to launch my home page, i see nothing. that makes me crazy.

Gareth Murfin

unread,
Aug 26, 2016, 5:22:37 AM8/26/16
to CodenameOne Discussions, usabg...@gmail.com
If you ever get it to work Id love to know how, I had to give up on FB altogether, I tell clients its not an option because i  couldnt get it to work on any level

usabg...@gmail.com

unread,
Aug 26, 2016, 8:29:17 AM8/26/16
to CodenameOne Discussions, usabg...@gmail.com
I'm trying to find a solution, everydays.

Gareth Murfin

unread,
Aug 26, 2016, 8:55:52 AM8/26/16
to CodenameOne Discussions, usabg...@gmail.com
good luck, I seem to remember the FK SDK is a nightmare even natively, I had once wrapped it all up entirely into a very simple object that could do everything nicely (for native android) if I can get back to that on Android I will make a lib, but it wont work on iOS.

Shai Almog

unread,
Aug 27, 2016, 1:56:09 AM8/27/16
to CodenameOne Discussions, usabg...@gmail.com
We have shipping apps with native facebook integration (quite a few) so I'm not exactly sure I understand what you guys are complaining about.
It's painful for sure but it's doable and there is a step by step guide in the developer guide.

Gareth Murfin

unread,
Aug 27, 2016, 6:06:29 AM8/27/16
to CodenameOne Discussions, usabg...@gmail.com
is the code for any of these apps available? We prob did something stupid, theres some old code around on google i think which confuses matters.

On 27 August 2016 at 13:56, Shai Almog <shai....@gmail.com> wrote:
We have shipping apps with native facebook integration (quite a few) so I'm not exactly sure I understand what you guys are complaining about.
It's painful for sure but it's doable and there is a step by step guide in the developer guide.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/Wi4Cwe9AS3U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/07904923-8c4f-45aa-b428-82170e0bb293%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Gareth Murfin
(Android Freelancer - www.garethmurfin.co.uk)

usabg...@gmail.com

unread,
Aug 27, 2016, 7:29:40 AM8/27/16
to CodenameOne Discussions, usabg...@gmail.com
my problem is , i have done anything for fk login, and i would like to do that, when the user succeed to connect with is facebook, he can connect in my app. But, when i push the facebook button, i see nothing, i only see the facebook connection, but after the facebook login form, the application stay on the connection form instead of go to the next form.

Shai Almog

unread,
Aug 28, 2016, 12:27:18 AM8/28/16
to CodenameOne Discussions, usabg...@gmail.com
Reply all
Reply to author
Forward
0 new messages