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(); } });
/* * 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);}
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.